Skip to content
Permalink
Browse files

Add 3Point Angle Dimension

  • Loading branch information...
WandererFan authored and yorikvanhavre committed Sep 30, 2018
1 parent 1578b05 commit b56912013176d2c47c9412ab4bdfda7a90c0091b
@@ -74,6 +74,7 @@ const char* DrawViewDimension::TypeEnums[]= {"Distance",
"Radius",
"Diameter",
"Angle",
"Angle3Pt",
NULL};

const char* DrawViewDimension::MeasureTypeEnums[]= {"True",
@@ -85,7 +86,8 @@ enum RefType{
oneEdge,
twoEdge,
twoVertex,
vertexEdge
vertexEdge,
threeVertex
};

DrawViewDimension::DrawViewDimension(void)
@@ -406,6 +408,32 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
pts.vertex = apex;
m_anglePoints = pts;
m_hasGeometry = true;
} else if(Type.isValue("Angle3Pt")){
if (getRefType() != threeVertex) {
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
return App::DocumentObject::StdReturn;
}
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
int idx1 = DrawUtil::getIndexFromName(subElements[1]);
int idx2 = DrawUtil::getIndexFromName(subElements[2]);

TechDrawGeometry::Vertex* vert0 = getViewPart()->getProjVertexByIndex(idx0);
TechDrawGeometry::Vertex* vert1 = getViewPart()->getProjVertexByIndex(idx1);
TechDrawGeometry::Vertex* vert2 = getViewPart()->getProjVertexByIndex(idx2);
if (!vert0 || !vert1 || !vert2) {
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
return App::DocumentObject::StdReturn;
}

anglePoints pts;
Base::Vector3d apex = vert1->getAs3D();
Base::Vector3d extPoint0 = vert0->getAs3D();
Base::Vector3d extPoint2 = vert2->getAs3D();
pts.ends.first = extPoint0;
pts.ends.second = extPoint2;
pts.vertex = apex;
m_anglePoints = pts;
m_hasGeometry = true;
}

//TODO: if MeasureType = Projected and the Projected shape changes, the Dimension may become invalid (see tilted Cube example)
@@ -559,6 +587,14 @@ double DrawViewDimension::getDimValue()
Base::Vector3d leg1 = pts.ends.second - vertex;
double legAngle = leg0.GetAngle(leg1) * 180.0 / M_PI;
result = legAngle;

} else if(Type.isValue("Angle3Pt")){ //same as case "Angle"?
anglePoints pts = m_anglePoints;
Base::Vector3d vertex = pts.vertex;
Base::Vector3d leg0 = pts.ends.first - vertex;
Base::Vector3d leg1 = pts.ends.second - vertex;
double legAngle = leg0.GetAngle(leg1) * 180.0 / M_PI;
result = legAngle;
}
}
return result;
@@ -662,6 +698,8 @@ int DrawViewDimension::getRefType() const
refType = getRefType1(subElements[0]);
} else if (subElements.size() == 2) {
refType = getRefType2(subElements[0],subElements[1]);
} else if (subElements.size() == 3) {
refType = getRefType3(subElements[0],subElements[1],subElements[2]);
}
return refType;
}
@@ -697,6 +735,21 @@ int DrawViewDimension::getRefType2(const std::string g1, const std::string g2)
return refType;
}

int DrawViewDimension::getRefType3(const std::string g1,
const std::string g2,
const std::string g3)
{
int refType = invalidRef;
if ((DrawUtil::getGeomTypeFromName(g1) == "Vertex") &&
(DrawUtil::getGeomTypeFromName(g2) == "Vertex") &&
(DrawUtil::getGeomTypeFromName(g3) == "Vertex") ) {
refType = threeVertex;
}

return refType;
}


//! validate 2D references - only checks if they exist, not if they are the right type
bool DrawViewDimension::checkReferences2D() const
{
@@ -126,6 +126,9 @@ class TechDrawExport DrawViewDimension : public TechDraw::DrawView
virtual QRectF getRect() const { return QRectF(0,0,1,1);} //pretend dimensions always fit!
static int getRefType1(const std::string s);
static int getRefType2(const std::string s1, const std::string s2);
static int getRefType3(const std::string g1,
const std::string g2,
const std::string g3);
int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge
void setAll3DMeasurement();
void clear3DMeasurements(void);
@@ -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";
}
Oops, something went wrong.

0 comments on commit b569120

Please sign in to comment.
You can’t perform that action at this time.