Add 3Point Angle Dimension
This commit is contained in:
committed by
Yorik van Havre
parent
1578b05a98
commit
b569120131
@@ -78,7 +78,8 @@ enum EdgeType{
|
||||
isEllipse,
|
||||
isBSplineCircle,
|
||||
isBSpline,
|
||||
isAngle
|
||||
isAngle,
|
||||
isAngle3Pt
|
||||
};
|
||||
|
||||
|
||||
@@ -92,7 +93,7 @@ bool _checkSelection(Gui::Command* cmd, unsigned maxObjs = 2);
|
||||
bool _checkDrawViewPart(Gui::Command* cmd);
|
||||
bool _checkPartFeature(Gui::Command* cmd);
|
||||
int _isValidSingleEdge(Gui::Command* cmd);
|
||||
bool _isValidVertexes(Gui::Command* cmd);
|
||||
bool _isValidVertexes(Gui::Command* cmd, int count = 2);
|
||||
int _isValidEdgeToEdge(Gui::Command* cmd);
|
||||
bool _isValidVertexToEdge(Gui::Command* cmd);
|
||||
char* _edgeTypeToText(int e);
|
||||
@@ -856,6 +857,96 @@ bool CmdTechDrawNewAngleDimension::isActive(void)
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_NewAngle3PtDimension
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdTechDrawNewAngle3PtDimension);
|
||||
|
||||
CmdTechDrawNewAngle3PtDimension::CmdTechDrawNewAngle3PtDimension()
|
||||
: Command("TechDraw_NewAngle3PtDimension")
|
||||
{
|
||||
sAppModule = "TechDraw";
|
||||
sGroup = QT_TR_NOOP("TechDraw");
|
||||
sMenuText = QT_TR_NOOP("Insert a new 3 point Angle dimension");
|
||||
sToolTipText = QT_TR_NOOP("Insert a new 3 point Angle dimension");
|
||||
sWhatsThis = "TechDraw_Dimension_Angle3Pt";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "TechDraw_Dimension_Angle3Pt";
|
||||
}
|
||||
|
||||
void CmdTechDrawNewAngle3PtDimension::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
bool result = _checkSelection(this,3);
|
||||
if (!result)
|
||||
return;
|
||||
result = _checkDrawViewPart(this);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = 0;
|
||||
std::vector<std::string> SubNames;
|
||||
|
||||
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
|
||||
for (; itSel != selection.end(); itSel++) {
|
||||
if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
|
||||
objFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
|
||||
SubNames = (*itSel).getSubNames();
|
||||
}
|
||||
}
|
||||
TechDraw::DrawPage* page = objFeat->findParentPage();
|
||||
std::string PageName = page->getNameInDocument();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
|
||||
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 {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
|
||||
QObject::tr("Need three points to make an 3 point Angle Dimension"));
|
||||
return;
|
||||
}
|
||||
|
||||
openCommand("Create Dimension");
|
||||
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
|
||||
,"Angle3Pt");
|
||||
|
||||
dim = dynamic_cast<TechDraw::DrawViewDimension *>(getDocument()->getObject(FeatName.c_str()));
|
||||
if (!dim) {
|
||||
throw Base::Exception("CmdTechDrawNewAngle3PtDimension - dim not found\n");
|
||||
}
|
||||
dim->References2D.setValues(objs, subs);
|
||||
|
||||
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
|
||||
|
||||
commitCommand();
|
||||
dim->recomputeFeature();
|
||||
|
||||
//Horrible hack to force Tree update
|
||||
double x = objFeat->X.getValue();
|
||||
objFeat->X.setValue(x);
|
||||
}
|
||||
|
||||
bool CmdTechDrawNewAngle3PtDimension::isActive(void)
|
||||
{
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
|
||||
//! link 3D geometry to Dimension(s) on a Page
|
||||
//TODO: should we present all potential Dimensions from all Pages?
|
||||
//===========================================================================
|
||||
@@ -948,6 +1039,7 @@ void CreateTechDrawCommandsDims(void)
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewDistanceXDimension());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewDistanceYDimension());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewAngleDimension());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewAngle3PtDimension());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawLinkDimension());
|
||||
}
|
||||
|
||||
@@ -1063,17 +1155,22 @@ int _isValidSingleEdge(Gui::Command* cmd) {
|
||||
return edgeType;
|
||||
}
|
||||
|
||||
//! verify that Selection contains valid geometries for a Vertex to Vertex Dimension
|
||||
bool _isValidVertexes(Gui::Command* cmd) {
|
||||
//! 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();
|
||||
if(SubNames.size() == 2) { //there are 2
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" && //they both start with "Vertex"
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
|
||||
return true;
|
||||
bool isValid = true;
|
||||
if(SubNames.size() == (unsigned) count) {
|
||||
for (auto& s: SubNames) {
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(s) != "Vertex") {
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isValid = false;
|
||||
}
|
||||
return false;
|
||||
return isValid;
|
||||
}
|
||||
|
||||
//! verify that the Selection contains valid geometries for an Edge to Edge Dimension
|
||||
@@ -1198,6 +1295,9 @@ char* _edgeTypeToText(int e)
|
||||
case isAngle:
|
||||
result = "angle";
|
||||
break;
|
||||
case isAngle3Pt:
|
||||
result = "angle3";
|
||||
break;
|
||||
default:
|
||||
result = "unknown";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user