20220513-20220608.QT
String转QString
string test = "dx:" + to_string(dx) + " dy:" + to_string(dy) + " dz:" + to_string(dz);
Show_Werld_Msg(QString::fromStdString(test));
string test = "部分保存成功,其余焊缝 ";
for (int j = 0; j < m_weldlineparas.size(); j++){
if (saveSuc[j][1] == 0){
test = test + " "+ to_string(saveSuc[j][0]) + ",";
}
}
test += "因缺少相关数据,保存失败!";
QMessageBox::information(NULL, QStringLiteral("提示"), QString::fromLocal8Bit(test.data()), QMessageBox::Yes);
原本QStringLiteral(“xxxxx”)用不了,原因解释QStringLiteral
两线段是否相交
bool ifinter = false;//默认不相交
//input a1, a2, a3 and all the other components here
//define all constants required for solving t and s
//(a1, a2, a3)________________(b1, b2, b3)
//Pa Pb
//and second line
//(c1, c2, c3)________________(d1, d2, d3)
//Pc Pd
WSPosParas Pa,Pb,Pc,Pd;
Pa = line1.at(0);
Pb = line1.at(line1.size() - 1);
Pa = line2.at(0);
Pb = line2.at(line2.size() - 1);
int a1 = Pa.pt[0], a2 = Pa.pt[1], a3 = Pa.pt[2];
int b1 = Pb.pt[0], b2 = Pb.pt[1], b3 = Pb.pt[2];
int c1 = Pc.pt[0], c2 = Pc.pt[1], c3 = Pc.pt[2];
int d1 = Pd.pt[0], d2 = Pd.pt[1], d3 = Pd.pt[2];
int A = b1 - a1;
int B = c1 - d1;
int C = c1 - a1;
int D = b2 - a2;
int E = c2 - d2;
int F = c2 - a2;
//#find t and s using formula
int t = (C*E - F*B) / (E*A - B*D);
int s = (D*C - A*F) / (D*B - A*E);
//#check if third equation is also satisfied(we have 3 equations and 2 variable
if ((t*(b3 - a3) + s*(c3 - d3)) == c3 - a3) {
if (0 <= t <= 1 && 0 <= s <= 1) {
ifinter = true;
}
}
四个点是否共面,两个直线是否相交
WSPosParas Pa,Pb,Pc,Pd;
Pa = line1.at(0);
Pb = line1.at(line1.size() - 1);
Pc = line2.at(0);
Pd = line2.at(line2.size() - 1);
int x1 = Pa.pt[0], y1 = Pa.pt[1], z1 = Pa.pt[2];
int x2 = Pb.pt[0], y2 = Pb.pt[1], z2 = Pb.pt[2];
int x3 = Pc.pt[0], y3 = Pc.pt[1], z3 = Pc.pt[2];
int x4 = Pd.pt[0], y4 = Pd.pt[1], z4 = Pd.pt[2];
int r1 = x1 - x2, r2 = y1 - y2, r3 = z1 - z2;
int r4 = x1 - x3, r5 = y1 - y3, r6 = z1 - z3;
int r7 = x1 - x4, r8 = y1 - y4, r9 = z1 - z4;
if (r1*r5*r9 + r2*r6*r7 + r3*r4*r8 - r3*r5*r7 - r2*r4*r9 - r1*r6*r8 == 0)
ifinter = true;
if (ifinter) Show_Werld_Msg(QStringLiteral("共面"));
else Show_Werld_Msg(QStringLiteral("异面"));
if (ifinter == FALSE)//不共面报错
return false;
git相关操作
右键选git bush啥啥啥,打开一个命令行一样的窗口
git log //查看所有日志
修改没有push的日志
git commit --amend
i //进去以后按,然后编辑完
:wq //退出就好了
push冲突时,先pull下来,手动改代码后,再上传
截图快捷键 shift+win+s
VS2013扩展工具不能联网
打开 nuget 控制台,输入下面代码,按回车,亲测有效,但是有个问题,就是关闭VS后,重新打开就会失去效果,需要再次输入代码,按回车才能生效。
[Net.ServicePointManager]::SecurityProtocol=[Net.ServicePointManager]::SecurityProtocol-bOR [Net.SecurityProtocolType]::Tls12
VS官方下载应用渠道
https://marketplace.visualstudio.com/search?target=VS&category=Tools&vsVersion=&subCategory=All&sortBy=Installs
memset初始化带有vector的结构体
struct Condition{
bool tmall;
long sales;
long min_price;
vector<wstring> filt_word_list;
//默认初始化
Condition(){tmall=false;sales=0;min_price=0;}
};
中文string乱码问题
方法二:VS菜单栏中选择工具—扩展和更新—联机—搜索插件“ForceUTF8”,有两个,选择 (with BOM)的并安装,以后VS所有源文件和头文件都会保存为“UTF-8+BOM”编码。
字母矩阵相乘
#include <iostream>//导入输入和输出的代码
#include <string>//能够写字符串的
#include <vector>//能够写字符串的
using namespace std;//应用命名空间 cout为输出 cin为输入
vector<vector<string>> mult(vector<vector<string>> &A, vector<vector<string>> &B,int order,bool islast){
vector<vector<string>> ans(order, vector<string>(order, ""));
for (int i = 0; i < order; i++){ //行数
for (int j = 0; j < order; j++){ //列数
//ans[行][列]
//if (ans[i][j] != "" && ans[i][j].length()>1) ans[i][j] = "(" + ans[i][j];
//if (ans[i][j][0] != '(' && ans[i][j].back() != ')') ans[i][j] = "(" + ans[i][j];
for (int z = 0; z < order; z++){
if (A[i][z] == "0" || A[i][z] == "" || B[z][j] == "0" || B[z][j] == "") continue;
if (ans[i][j] != "") ans[i][j] += "+";
if (A[i][z] == "1" && B[z][j] == "1") ans[i][j] = ans[i][j] + A[i][z];
else{
if (A[i][z] == "1") ans[i][j] += B[z][j];
else if (B[z][j] == "1") ans[i][j] += A[i][z];
else ans[i][j] = ans[i][j] + A[i][z] + "*" + B[z][j];
}
}
if (!islast && ans[i][j] != "" && ans[i][j].back() != ')'){
if (ans[i][j] != "" && ans[i][j].length()>3) ans[i][j] = "(" + ans[i][j];
if (ans[i][j] != "" && ans[i][j].length()>3) ans[i][j] += ")";
}
//if (ans[i][j] != "" && ans[i][j].back() != ')' && ans[i][j].length()>1) ans[i][j] += ")";
}
}
return ans;
}
int main()
{
int matrixNum = 8;
int order = 4;
vector<vector<string>> test1(3, vector<string>(3, ""));
vector<vector<string>> test2(3, vector<string>(3, ""));
vector<vector<string>> test(3, vector<string>(3, ""));
test1 = { { "1", "1", "1" }, { "1", "1", "1" }, { "1", "1", "1" } };
test2 = { { "1", "a", "1" }, { "1", "b", "1" }, { "1", "c", "1" } };
test = mult(test1, test2, 3,true);
//for (int i = 0; i < 3; i++){
// for (int j = 0; j < 3; j++){
// cout << test[i][j] << " " << endl;
// }
// cout << endl;
//}
vector<vector<vector<string>>> matall(matrixNum, vector<vector<string>>(order, vector<string>(4, "")));
vector<vector<string>> matans(order, vector<string>(order, ""));
matall[0] = { { "1", "0", "0", "0" }, { "0", "0", "1", "d1" }, { "0", "1", "0", "0" }, { "0", "0", "0", "1" } };
matall[1] = { { "0", "0", "1", "B" }, { "0", "1", "0", "A" }, { "1", "0", "0", "0" }, { "0", "0", "0", "1" } };
matall[2] = { { "1", "0", "0", "0" }, { "0", "0", "-1", "-L3" }, { "0", "1", "0", "R3" }, { "0", "0", "0", "1" } };
matall[3] = { { "c4", "0", "s4", "R4c4" }, { "s4", "0", "-c4", "R4s4" }, { "0", "1", "0", "L4" }, { "0", "0", "0", "1" } };
matall[4] = { { "c5", "s5", "0", "R5c5" }, { "s5", "-c5", "0", "R5s5" }, { "0", "0", "1", "L5" }, { "0", "0", "0", "1" } };
matall[5] = { { "c6", "0", "-s6", "R6c6" }, { "s6", "0", "c6", "R6s6" }, { "0", "1", "1", "-L6" }, { "0", "0", "0", "1" } };
matall[6] = { { "c7", "-s7", "0", "0" }, { "s7", "c7", "0", "0" }, { "0", "0", "1", "L7" }, { "0", "0", "0", "1" } };
matall[7] = { { "c8", "-s8", "0", "0" }, { "s8", "c8", "0", "0" }, { "0", "0", "1", "L8" }, { "0", "0", "0", "1" } };
matans = matall[0];
for (int i = 1; i < matrixNum; i++){
if (i == matrixNum-1) matans = mult(matans, matall[i], order, true);
else matans = mult(matans, matall[i], order,false);
}
//cout << matans[0][0];
for (int i = 0; i < order; i++){
for (int j = 0; j < order; j++){
cout << "T" << i+1<<j+1<<": ";
if (matans[i][j] == "") cout << "0" << endl;
else cout << matans[i][j] << " " << endl;
}
cout << endl;
cout << endl;
//cout << endl;
//cout << endl;
}
return 0;
}
数据库验证加弹窗消息
调用
SaveTechParaMes(IsSaveTechParaSuc()); //20220607LYT#bug052
实现
void IFWRobotDemo::SaveTechParaMes(vector<vector<int>> & saveState){//右下角弹窗提示消息,20220607LYT#bug052
int len = saveState.size();
bool saveExist = false;
bool lostExist = false;
for (int i = 0; i < len; i++){ //两个标志位防止空消息
if (saveState[i][1] == 1) saveExist = true;
if (saveState[i][1] == 0) lostExist = true;
}
string test = "";
test = "焊缝" + MesSelectSecN(1, saveState) + "保存成功! ";
if(saveExist) Show_Werld_Msg(QString::fromLocal8Bit(test.data()));
test = "焊缝" + MesSelectSecN(0, saveState) + "工艺数据缺失,保存失败! ";
if(lostExist) Show_Werld_Msg(QString::fromLocal8Bit(test.data()));
//test = "焊缝" + MesSelectSecN(2, saveState) + "无工作面,不做处理";
//Show_Werld_Msg(QString::fromLocal8Bit(test.data()));
}
vector<vector<int>> IFWRobotDemo::IsSaveTechParaSuc(){ //判断数据库是否写入工艺数据,一次判断一条id,20220607LYT#bug052
vector<vector<int>> State(m_weldlineparas.size(), { 100, 0 });
QSqlQuery query;
for (int i = 0; i < m_weldlineparas.size(); i++)
{
int weldseam_id = m_weldlineparas.at(i).weld_num;//焊缝编号
State[i][0] = weldseam_id;
QString sql;
if (0 == m_weldlineparas.at(i).tech.WorkFace | 0 == m_weldlineparas.at(i).tech.WeldArea) //2缺少作业面,肯定没保存,不用访问数据库
{
State[i][1] = 2;
}
else{ //有作业面,访问数据库判断有没有保存
sql = QString("select * from Task_TechPara where workpiece_name='%1' and weld_seam_id = %2").arg(m_strWName).arg(weldseam_id);
query.exec(sql);
if (query.next()){
State[i][1] = 1;
}
}
}
return State;
}
string IFWRobotDemo::MesBeginToEnd(int begin, int end){ //实现连号输出,1,2,3变成1-3, LYT20220526#bug052-----
string Mes = "";
//if (begin > end) return Mes;
if (begin == end){
Mes = to_string(end); //1-1就写成1
}
else if (begin == end-1){
Mes = to_string(begin) + "、" + to_string(end) ;
}
else{
Mes = to_string(begin) + "-" + to_string(end); //1-2
}
return Mes;
}
string IFWRobotDemo::MesSelectSecN(int SecN, vector<vector<int>> & vec){ //筛选二维vector指定1位置值的所有0位置的值, LYT20220526#bug052-----
int startnum = -2, lastnum = -2;//实现连号输出,1,2,3变成1-3
int veclen = vec.size();
string Mes = "";
if (veclen == 0) return Mes;
for (int j = 0; j < veclen; j++){
if (vec[j][1] == SecN){ //筛选
if (startnum == -2){ //第1个异常,赋值
startnum = vec[j][0];
lastnum = startnum;
}
else{ //第2-n个异常,更新或输出
if (vec[j][0] == lastnum + 1){ //可以连号
lastnum++; //更新末端
}
else{ //不能连号,需要输出,更新首末端
Mes = Mes + MesBeginToEnd(startnum, lastnum) + "、";
startnum = vec[j][0];
lastnum = startnum;
}
}
}
if (j == veclen - 1){//如果当前是最后一个,需要输出
Mes += MesBeginToEnd(startnum, lastnum);
}
}
return Mes;
}