[TechDraw] Improve readability of commands

This commit is contained in:
Benjamin Bræstrup Sayoc
2022-07-09 03:49:20 +02:00
committed by WandererFan
parent bf606e980c
commit 8c0ab46b4d
5 changed files with 737 additions and 751 deletions

View File

@@ -851,12 +851,11 @@ void exec2LineCenterLine(Gui::Command* cmd)
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("Selection is not a CenterLine."));
return;
} else {
Gui::Control().showDialog(new TaskDlgCenterLine(dvp,
page,
selectedEdges.front(),
true));
}
Gui::Control().showDialog(new TaskDlgCenterLine(dvp,
page,
selectedEdges.front(),
true));
} else { //not create, not edit, what is this???
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("Selection not understood."));
@@ -914,17 +913,17 @@ void exec2PointCenterLine(Gui::Command* cmd)
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* baseFeat = nullptr;
if (!selection.empty()) {
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("No base View in Selection."));
return;
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("You must select a base View for the line."));
return;
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("You must select a base View for the line."));
return;
}
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("No base View in Selection."));
return;
}
std::vector<std::string> subNames;
@@ -1030,28 +1029,28 @@ void execLine2Points(Gui::Command* cmd)
TechDraw::DrawViewPart* baseFeat = nullptr;
std::vector<std::string> subNames2D;
std::vector< std::pair<Part::Feature*, std::string> > objs3D;
if (!selection.empty()) {
for (auto& so: selection) {
if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
baseFeat = static_cast<TechDraw::DrawViewPart*> (so.getObject());
subNames2D = so.getSubNames();
} else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
std::vector<std::string> subNames3D = so.getSubNames();
for (auto& sub3D: subNames3D) {
std::pair<Part::Feature*, std::string> temp;
temp.first = static_cast<Part::Feature*>(so.getObject());
temp.second = sub3D;
objs3D.push_back(temp);
}
} else {
//garbage
}
}
} else {
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("Selection is empty."));
return;
}
for (auto& so: selection) {
if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
baseFeat = static_cast<TechDraw::DrawViewPart*> (so.getObject());
subNames2D = so.getSubNames();
} else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
std::vector<std::string> subNames3D = so.getSubNames();
for (auto& sub3D: subNames3D) {
std::pair<Part::Feature*, std::string> temp;
temp.first = static_cast<Part::Feature*>(so.getObject());
temp.second = sub3D;
objs3D.push_back(temp);
}
} else {
//garbage
}
}
if (baseFeat == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
@@ -1133,6 +1132,10 @@ void execLine2Points(Gui::Command* cmd)
// TechDraw_CosmeticEraser
//===========================================================================
#define GEOMETRYEDGE 0
#define COSMETICEDGE 1
#define CENTERLINE 2
DEF_STD_CMD_A(CmdTechDrawCosmeticEraser)
CmdTechDrawCosmeticEraser::CmdTechDrawCosmeticEraser()
@@ -1170,19 +1173,14 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg)
return;
}
bool selectionError = false;
for (auto& s: selection) {
TechDraw::DrawViewPart * objFeat = static_cast<TechDraw::DrawViewPart*> (s.getObject());
if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
selectionError = true;
break;
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("At least 1 object in selection is not a part view"));
return;
}
}
if (selectionError) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("At least 1 object in selection is not a part view"));
return;
}
TechDraw::DrawViewPart * objFeat = nullptr;
std::vector<std::string> subNames;
@@ -1207,9 +1205,9 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg)
(bg->cosmetic) ) {
int source = bg->source();
std::string tag = bg->getCosmeticTag();
if (source == 1) { //this is a "CosmeticEdge"
if (source == COSMETICEDGE) {
ce2Delete.push_back(tag);
} else if (source == 2) { //this is a "CenterLine"
} else if (source == CENTERLINE) {
cl2Delete.push_back(tag);
} else {
Base::Console().Message(
@@ -1218,16 +1216,15 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg)
}
} else if (geomType == "Vertex") {
TechDraw::VertexPtr tdv = objFeat->getProjVertexByIndex(idx);
if (tdv != nullptr) {
std::string delTag = tdv->cosmeticTag;
if (!delTag.empty()) {
cv2Delete.push_back(delTag);
} else {
Base::Console().Warning("Vertex%d is not cosmetic! Can not erase.\n", idx);
}
} else {
if (tdv == nullptr) {
Base::Console().Message("CMD::eraser - geom: %d not found!\n", idx);
}
std::string delTag = tdv->cosmeticTag;
if (delTag.empty()) {
Base::Console().Warning("Vertex%d is not cosmetic! Can not erase.\n", idx);
}
cv2Delete.push_back(delTag);
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Unknown object type in selection"));
@@ -1292,17 +1289,17 @@ void CmdTechDrawDecorateLine::activated(int iMsg)
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
TechDraw::DrawViewPart* baseFeat = nullptr;
if (!selection.empty()) {
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("No View in Selection."));
return;
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("You must select a View and/or lines."));
return;
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("You must select a View and/or lines."));
return;
}
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
QObject::tr("No View in Selection."));
return;
}
std::vector<std::string> subNames;
@@ -1370,19 +1367,19 @@ void CmdTechDrawShowAll::activated(int iMsg)
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
TechDraw::DrawViewPart* baseFeat = nullptr;
if (!selection.empty()) {
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if (baseFeat == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Part Views in this selection"));
return;
}
} else { //empty selection
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Nothing selected"));
return;
}
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if (baseFeat == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Part Views in this selection"));
return;
}
Gui::ViewProvider* vp = QGIView::getViewProvider(baseFeat);
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
if ( partVP != nullptr ) {

View File

@@ -405,18 +405,12 @@ void CmdTechDrawDiameterDimension::activated(int iMsg)
std::vector<std::string> subs;
int edgeType = _isValidSingleEdge(this);
if (edgeType == isCircle) {
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else if (edgeType == isEllipse) {
if (edgeType == isEllipse) {
QMessageBox::StandardButton result =
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Ellipse Curve Warning"),
QObject::tr("Selected edge is an Ellipse. Diameter will be approximate. Continue?"),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
if (result == QMessageBox::Ok) {
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else {
if (result != QMessageBox::Ok) {
return;
}
} else if (edgeType == isBSplineCircle) {
@@ -424,10 +418,7 @@ void CmdTechDrawDiameterDimension::activated(int iMsg)
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("BSpline Curve Warning"),
QObject::tr("Selected edge is a BSpline. Diameter will be approximate. Continue?"),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
if (result == QMessageBox::Ok) {
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else {
if (result != QMessageBox::Ok) {
return;
}
} else if (edgeType == isBSpline) {
@@ -443,6 +434,9 @@ void CmdTechDrawDiameterDimension::activated(int iMsg)
return;
}
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Dimension"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
@@ -827,16 +821,16 @@ void CmdTechDrawAngleDimension::activated(int iMsg)
std::vector<std::string> subs;
int edgeType = _isValidEdgeToEdge(this);
if (edgeType == isAngle) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else {
if (edgeType != isAngle) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr("Need two straight edges to make an Angle Dimension"));
return;
}
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Dimension"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
@@ -914,19 +908,19 @@ void CmdTechDraw3PtAngleDimension::activated(int iMsg)
std::vector<App::DocumentObject *> objs;
std::vector<std::string> subs;
if (_isValidVertexes(this, 3)) {
objs.push_back(objFeat);
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
subs.push_back(SubNames[2]);
} else {
if (!_isValidVertexes(this, 3)) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr("Need three points to make a 3 point Angle Dimension"));
return;
}
objs.push_back(objFeat);
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
subs.push_back(SubNames[2]);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Dimension"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
@@ -1176,17 +1170,17 @@ void execHExtent(Gui::Command* cmd)
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* baseFeat = nullptr;
if (!selection.empty()) {
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("No base View in Selection."));
return;
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("Please select a View [and Edges]."));
return;
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("Please select a View [and Edges]."));
return;
}
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("No base View in Selection."));
return;
}
std::vector<std::string> SubNames;
@@ -1263,17 +1257,18 @@ void execVExtent(Gui::Command* cmd)
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* baseFeat = nullptr;
if (!selection.empty()) {
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("No base View in Selection."));
return;
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("Please select a View [and Edges]."));
return;
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("Please select a View [and Edges]."));
return;
}
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
if( baseFeat == nullptr ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"),
QObject::tr("No base View in Selection."));
return;
}
std::vector<std::string> SubNames;
@@ -1475,7 +1470,6 @@ bool _checkPartFeature(Gui::Command* cmd) {
//! verify that Selection contains a valid Geometry for a single Edge Dimension
int _isValidSingleEdge(Gui::Command* cmd) {
auto edgeType( isInvalid );
auto selection( cmd->getSelection().getSelectionEx() );
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
@@ -1484,65 +1478,68 @@ int _isValidSingleEdge(Gui::Command* cmd) {
}
const std::vector<std::string> SubNames = selection[0].getSubNames();
if (SubNames.size() == 1) { //only 1 subshape selected
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge"
int GeoId( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId);
if (!geom) {
Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId);
return isInvalid;
}
if (SubNames.size() != 1 ||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") {
return isInvalid;
}
if(geom->geomType == TechDraw::GENERIC) {
TechDraw::GenericPtr gen1 = std::static_pointer_cast<TechDraw::Generic>(geom);
if(gen1->points.size() > 2) { //the edge is a polyline
return isInvalid;
}
Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0);
if(fabs(line.y) < FLT_EPSILON ) {
edgeType = isHorizontal;
} else if(fabs(line.x) < FLT_EPSILON) {
edgeType = isVertical;
} else {
edgeType = isDiagonal;
}
} else if (geom->geomType == TechDraw::CIRCLE ||
geom->geomType == TechDraw::ARCOFCIRCLE ) {
edgeType = isCircle;
} else if (geom->geomType == TechDraw::ELLIPSE ||
geom->geomType == TechDraw::ARCOFELLIPSE) {
edgeType = isEllipse;
} else if (geom->geomType == TechDraw::BSPLINE) {
TechDraw::BSplinePtr spline = static_pointer_cast<TechDraw::BSpline> (geom);
if (spline->isCircle()) {
edgeType = isBSplineCircle;
} else {
edgeType = isBSpline;
}
} else {
edgeType = isInvalid;
}
//only 1 subshape selected
//the Name starts with "Edge"
int GeoId( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId);
if (!geom) {
Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId);
return isInvalid;
}
if(geom->geomType == TechDraw::GENERIC) {
TechDraw::GenericPtr gen1 = std::static_pointer_cast<TechDraw::Generic>(geom);
if(gen1->points.size() > 2) { //the edge is a polyline
return isInvalid;
}
Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0);
if(fabs(line.y) < FLT_EPSILON ) {
return isHorizontal;
} else if(fabs(line.x) < FLT_EPSILON) {
return isVertical;
} else {
return isDiagonal;
}
} else if (geom->geomType == TechDraw::CIRCLE ||
geom->geomType == TechDraw::ARCOFCIRCLE ) {
return isCircle;
} else if (geom->geomType == TechDraw::ELLIPSE ||
geom->geomType == TechDraw::ARCOFELLIPSE) {
return isEllipse;
} else if (geom->geomType == TechDraw::BSPLINE) {
TechDraw::BSplinePtr spline = static_pointer_cast<TechDraw::BSpline> (geom);
if (spline->isCircle()) {
return isBSplineCircle;
} else {
return isBSpline;
}
}
return edgeType;
return isInvalid;
}
//! verify that Selection contains valid geometries for a Vertex based Dimensions
bool _isValidVertexes(Gui::Command* cmd, int count) {
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
const std::vector<std::string> SubNames = selection[0].getSubNames();
bool isValid = true;
if(SubNames.size() == (unsigned) count) {
for (auto& s: SubNames) {
if (TechDraw::DrawUtil::getGeomTypeFromName(s) != "Vertex") {
isValid = false;
break;
}
}
} else {
isValid = false;
if(SubNames.size() != (unsigned) count) {
return false;
}
return isValid;
for (auto& s: SubNames) {
if (TechDraw::DrawUtil::getGeomTypeFromName(s) != "Vertex") {
return false;
}
}
return true;
}
//! verify that the Selection contains valid geometries for an Edge to Edge Dimension
@@ -1556,115 +1553,113 @@ int _isValidEdgeToEdge(Gui::Command* cmd) {
return isInvalid;
}
int edgeType = isInvalid;
const std::vector<std::string> SubNames = selection[0].getSubNames();
if(SubNames.size() == 2) { //there are 2
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
int GeoId0( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
int GeoId1( TechDraw::DrawUtil::getIndexFromName(SubNames[1]) );
TechDraw::BaseGeomPtr geom0 = objFeat0->getGeomByIndex(GeoId0);
TechDraw::BaseGeomPtr geom1 = objFeat0->getGeomByIndex(GeoId1);
if ((!geom0) || (!geom1)) { // missing gometry
Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1);
return isInvalid;
}
//there has to be 2
if(SubNames.size() != 2) {
return isInvalid;
}
if(geom0->geomType == TechDraw::GENERIC &&
geom1->geomType == TechDraw::GENERIC) {
TechDraw::GenericPtr gen0 = std::static_pointer_cast<TechDraw::Generic> (geom0);
TechDraw::GenericPtr gen1 = std::static_pointer_cast<TechDraw::Generic> (geom1);
if(gen0->points.size() > 2 ||
gen1->points.size() > 2) { //the edge is a polyline
return isInvalid; //not supported yet
}
Base::Vector3d line0 = gen0->points.at(1) - gen0->points.at(0);
Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0);
double xprod = fabs(line0.x * line1.y - line0.y * line1.x);
if (xprod > FLT_EPSILON) { //edges are not parallel
return isAngle; //angle or distance
} else {
return isDiagonal; //distance || line
}
} else {
return isDiagonal; //two edges, not both straight lines
}
} //edges
} // 2 sub objects
return edgeType;
//they both start with "Edge"
if(TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
return isInvalid;
}
int GeoId0( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
int GeoId1( TechDraw::DrawUtil::getIndexFromName(SubNames[1]) );
TechDraw::BaseGeomPtr geom0 = objFeat0->getGeomByIndex(GeoId0);
TechDraw::BaseGeomPtr geom1 = objFeat0->getGeomByIndex(GeoId1);
if ((!geom0) || (!geom1)) { // missing gometry
Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1);
return isInvalid;
}
if(geom0->geomType == TechDraw::GENERIC &&
geom1->geomType == TechDraw::GENERIC) {
TechDraw::GenericPtr gen0 = std::static_pointer_cast<TechDraw::Generic> (geom0);
TechDraw::GenericPtr gen1 = std::static_pointer_cast<TechDraw::Generic> (geom1);
if(gen0->points.size() > 2 ||
gen1->points.size() > 2) { //the edge is a polyline
return isInvalid; //not supported yet
}
Base::Vector3d line0 = gen0->points.at(1) - gen0->points.at(0);
Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0);
double xprod = fabs(line0.x * line1.y - line0.y * line1.x);
if (xprod > FLT_EPSILON) { //edges are not parallel
return isAngle; //angle or distance
} else {
return isDiagonal; //distance || line
}
} else {
return isDiagonal; //two edges, not both straight lines
}
return isInvalid;
}
//! verify that the Selection contains valid geometries for a Vertex to Edge Dimension
bool _isValidVertexToEdge(Gui::Command* cmd) {
bool result = false;
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* objFeat0 = static_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
const std::vector<std::string> SubNames = selection[0].getSubNames();
if(SubNames.size() == 2) { //there are 2
int eId,vId;
TechDraw::BaseGeomPtr e;
TechDraw::VertexPtr v;
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
eId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
vId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
} else if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge" &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex") {
eId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
vId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
} else {
return false;
}
e = objFeat0->getGeomByIndex(eId);
v = objFeat0->getProjVertexByIndex(vId);
if ((!e) || (!v)) {
Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",eId,vId);
return false;
}
result = true;
//there has to be 2
if(SubNames.size() != 2) {
return false;
}
return result;
int eId,vId;
TechDraw::BaseGeomPtr e;
TechDraw::VertexPtr v;
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
eId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
vId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
} else if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge" &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex") {
eId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
vId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
} else {
return false;
}
e = objFeat0->getGeomByIndex(eId);
v = objFeat0->getProjVertexByIndex(vId);
if ((!e) || (!v)) {
Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",eId,vId);
return false;
}
return true;
}
char* _edgeTypeToText(int e)
{
char* result;
switch(e) {
case isInvalid:
result = "invalid";
break;
return "invalid";
case isHorizontal:
result = "horizontal";
break;
return "horizontal";
case isVertical:
result = "vertical";
break;
return "vertical";
case isDiagonal:
result = "diagonal";
break;
return "diagonal";
case isCircle:
result = "circle";
break;
return "circle";
case isEllipse:
result = "ellipse";
break;
return "ellipse";
case isBSpline:
result = "bspline";
break;
return "bspline";
case isBSplineCircle:
result = "circular bspline";
break;
return "circular bspline";
case isAngle:
result = "angle";
break;
return "angle";
case isAngle3Pt:
result = "angle3";
break;
return "angle3";
default:
result = "unknown";
return "unknown";
}
return result;
}

View File

@@ -125,10 +125,10 @@ void CmdTechDrawHatch::activated(int iMsg)
QObject::tr("Some Faces in selection are already hatched. Replace?"));
if (rc == QMessageBox::StandardButton::NoButton) {
return;
} else {
removeOld = true;
break;
}
removeOld = true;
break;
}
}
@@ -276,17 +276,18 @@ void CmdTechDrawImage::activated(int iMsg)
QString(),
QString::fromUtf8(QT_TR_NOOP("Image (*.png *.jpg *.jpeg)")));
if (!fileName.isEmpty())
{
std::string FeatName = getUniqueObjectName("Image");
fileName = Base::Tools::escapeEncodeFilename(fileName);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Image"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewImage','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),fileName.toUtf8().constData());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
updateActive();
commitCommand();
if (fileName.isEmpty()) {
return;
}
std::string FeatName = getUniqueObjectName("Image");
fileName = Base::Tools::escapeEncodeFilename(fileName);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Image"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewImage','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),fileName.toUtf8().constData());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
updateActive();
commitCommand();
}
bool CmdTechDrawImage::isActive(void)
@@ -325,13 +326,12 @@ void CmdTechDrawToggleFrame::activated(int iMsg)
Gui::ViewProvider* vp = activeGui->getViewProvider(page);
ViewProviderPage* vpp = dynamic_cast<ViewProviderPage*>(vp);
if (vpp != nullptr) {
vpp->toggleFrameState();
} else {
if (vpp == nullptr) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No TechDraw Page"),
QObject::tr("Need a TechDraw Page for this command"));
return;
}
vpp->toggleFrameState();
}
bool CmdTechDrawToggleFrame::isActive(void)

File diff suppressed because it is too large Load Diff

View File

@@ -1901,24 +1901,23 @@ namespace TechDrawGui {
TechDraw::DrawViewPart*& objFeat,
std::string message) {
// check selection of getSelectionEx() and selection[0].getObject()
bool OK = true;
selection = cmd->getSelection().getSelectionEx();
if (selection.empty()) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr(message.c_str()),
QObject::tr("Selection is empty"));
OK = false;
return false;
}
if (OK) {
objFeat = dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject());
if (objFeat == nullptr) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr(message.c_str()),
QObject::tr("No object selected"));
OK = false;
}
objFeat = dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject());
if (objFeat == nullptr) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr(message.c_str()),
QObject::tr("No object selected"));
return false;
}
return OK;
return true;
}
std::vector<Base::Vector3d> _getVertexPoints(std::vector<std::string> SubNames, TechDraw::DrawViewPart* objFeat) {
@@ -1964,17 +1963,16 @@ namespace TechDrawGui {
int GeoId = TechDraw::DrawUtil::getIndexFromName(Name);
TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId);
std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name);
if (GeoType == "Edge") {
if (geom->geomType == TechDraw::CIRCLE) {
TechDraw::CirclePtr cgen = std::static_pointer_cast<TechDraw::Circle> (geom);
Base::Vector3d center = cgen->center;
float radius = cgen->radius;
TechDraw::BaseGeomPtr threadArc =
std::make_shared<TechDraw::AOC>(center / scale, radius * factor / scale, 255.0, 165.0);
std::string arcTag = objFeat->addCosmeticEdge(threadArc);
TechDraw::CosmeticEdge* arc = objFeat->getCosmeticEdge(arcTag);
_setLineAttributes(arc);
}
if (GeoType == "Edge" && geom->geomType == TechDraw::CIRCLE) {
TechDraw::CirclePtr cgen = std::static_pointer_cast<TechDraw::Circle> (geom);
Base::Vector3d center = cgen->center;
float radius = cgen->radius;
TechDraw::BaseGeomPtr threadArc =
std::make_shared<TechDraw::AOC>(center / scale, radius * factor / scale, 255.0, 165.0);
std::string arcTag = objFeat->addCosmeticEdge(threadArc);
TechDraw::CosmeticEdge* arc = objFeat->getCosmeticEdge(arcTag);
_setLineAttributes(arc);
}
}
@@ -1988,39 +1986,38 @@ namespace TechDrawGui {
int GeoId1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
TechDraw::BaseGeomPtr geom0 = objFeat->getGeomByIndex(GeoId0);
TechDraw::BaseGeomPtr geom1 = objFeat->getGeomByIndex(GeoId1);
if ((geom0->geomType == TechDraw::GENERIC) && (geom1->geomType == TechDraw::GENERIC)) {
TechDraw::GenericPtr line0 = std::static_pointer_cast<TechDraw::Generic> (geom0);
TechDraw::GenericPtr line1 = std::static_pointer_cast<TechDraw::Generic> (geom1);
Base::Vector3d start0 = line0->points.at(0);
Base::Vector3d end0 = line0->points.at(1);
Base::Vector3d start1 = line1->points.at(0);
Base::Vector3d end1 = line1->points.at(1);
if (DrawUtil::circulation(start0, end0, start1) != DrawUtil::circulation(end0, end1, start1)) {
Base::Vector3d help1 = start1;
Base::Vector3d help2 = end1;
start1 = help2;
end1 = help1;
}
start0.y = -start0.y;
end0.y = -end0.y;
start1.y = -start1.y;
end1.y = -end1.y;
float kernelDiam = (start1 - start0).Length();
float kernelFactor = (kernelDiam * factor - kernelDiam) / 2;
Base::Vector3d delta = (start1 - start0).Normalize() * kernelFactor;
std::string line0Tag = objFeat->addCosmeticEdge((start0 - delta) / scale, (end0 - delta) / scale);
std::string line1Tag = objFeat->addCosmeticEdge((start1 + delta) / scale, (end1 + delta) / scale);
TechDraw::CosmeticEdge* cosTag0 = objFeat->getCosmeticEdge(line0Tag);
TechDraw::CosmeticEdge* cosTag1 = objFeat->getCosmeticEdge(line1Tag);
_setLineAttributes(cosTag0);
_setLineAttributes(cosTag1);
}
else {
if (geom0->geomType != TechDraw::GENERIC || geom1->geomType != TechDraw::GENERIC) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("TechDraw Thread Hole Side"),
QObject::tr("Please select two straight lines"));
return;
}
TechDraw::GenericPtr line0 = std::static_pointer_cast<TechDraw::Generic> (geom0);
TechDraw::GenericPtr line1 = std::static_pointer_cast<TechDraw::Generic> (geom1);
Base::Vector3d start0 = line0->points.at(0);
Base::Vector3d end0 = line0->points.at(1);
Base::Vector3d start1 = line1->points.at(0);
Base::Vector3d end1 = line1->points.at(1);
if (DrawUtil::circulation(start0, end0, start1) != DrawUtil::circulation(end0, end1, start1)) {
Base::Vector3d help1 = start1;
Base::Vector3d help2 = end1;
start1 = help2;
end1 = help1;
}
start0.y = -start0.y;
end0.y = -end0.y;
start1.y = -start1.y;
end1.y = -end1.y;
float kernelDiam = (start1 - start0).Length();
float kernelFactor = (kernelDiam * factor - kernelDiam) / 2;
Base::Vector3d delta = (start1 - start0).Normalize() * kernelFactor;
std::string line0Tag = objFeat->addCosmeticEdge((start0 - delta) / scale, (end0 - delta) / scale);
std::string line1Tag = objFeat->addCosmeticEdge((start1 + delta) / scale, (end1 + delta) / scale);
TechDraw::CosmeticEdge* cosTag0 = objFeat->getCosmeticEdge(line0Tag);
TechDraw::CosmeticEdge* cosTag1 = objFeat->getCosmeticEdge(line1Tag);
_setLineAttributes(cosTag0);
_setLineAttributes(cosTag1);
}
}