diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 62f2fc7404c2..4235cd289780 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1003,6 +1003,7 @@ void ViewProviderSketch::editDoubleClicked(void) Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY || Constr->Type == Sketcher::Radius || + Constr->Type == Sketcher::Diameter || Constr->Type == Sketcher::Angle || Constr->Type == Sketcher::SnellsLaw)) { @@ -1228,7 +1229,7 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo #endif if (Constr->Type == Distance || Constr->Type == DistanceX || Constr->Type == DistanceY || - Constr->Type == Radius) { + Constr->Type == Radius || Constr->Type == Diameter) { Base::Vector3d p1(0.,0.,0.), p2(0.,0.,0.); if (Constr->SecondPos != Sketcher::none) { // point to point distance @@ -1257,7 +1258,9 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo } else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { const Part::GeomArcOfCircle *arc = static_cast(geo); double radius = arc->getRadius(); - p1 = arc->getCenter(); + Base::Vector3d center = arc->getCenter(); + p1 = center; + double angle = Constr->LabelPosition; if (angle == 10) { double startangle, endangle; @@ -1268,15 +1271,25 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo Base::Vector3d tmpDir = Base::Vector3d(toPos.x, toPos.y, 0) - p1; angle = atan2(tmpDir.y, tmpDir.x); } - p2 = p1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); + + if(Constr->Type == Sketcher::Diameter) + p1 = center - radius * Base::Vector3d(cos(angle),sin(angle),0.); + + p2 = center + radius * Base::Vector3d(cos(angle),sin(angle),0.); } else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { const Part::GeomCircle *circle = static_cast(geo); double radius = circle->getRadius(); - p1 = circle->getCenter(); + Base::Vector3d center = circle->getCenter(); + p1 = center; + Base::Vector3d tmpDir = Base::Vector3d(toPos.x, toPos.y, 0) - p1; double angle = atan2(tmpDir.y, tmpDir.x); - p2 = p1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); + + if(Constr->Type == Sketcher::Diameter) + p1 = center - radius * Base::Vector3d(cos(angle),sin(angle),0.); + + p2 = center + radius * Base::Vector3d(cos(angle),sin(angle),0.); } else return; @@ -1286,14 +1299,14 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo Base::Vector3d vec = Base::Vector3d(toPos.x, toPos.y, 0) - p2; Base::Vector3d dir; - if (Constr->Type == Distance || Constr->Type == Radius) + if (Constr->Type == Distance || Constr->Type == Radius || Constr->Type == Diameter) dir = (p2-p1).Normalize(); else if (Constr->Type == DistanceX) dir = Base::Vector3d( (p2.x - p1.x >= FLT_EPSILON) ? 1 : -1, 0, 0); else if (Constr->Type == DistanceY) dir = Base::Vector3d(0, (p2.y - p1.y >= FLT_EPSILON) ? 1 : -1, 0); - if (Constr->Type == Radius) { + if (Constr->Type == Radius || Constr->Type == Diameter) { Constr->LabelDistance = vec.x * dir.x + vec.y * dir.y; Constr->LabelPosition = atan2(dir.y, dir.x); } else { @@ -2651,6 +2664,7 @@ void ViewProviderSketch::updateColor(void) ConstraintType type = constraint->Type; bool hasDatumLabel = (type == Sketcher::Angle || type == Sketcher::Radius || + type == Sketcher::Diameter || type == Sketcher::Symmetric || type == Sketcher::Distance || type == Sketcher::DistanceX || @@ -4993,7 +5007,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer } break; - case Radius: + case Diameter: { assert(Constr->First >= -extGeoCount && Constr->First < intGeoCount); @@ -5010,8 +5024,9 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer arc->getRange(startangle, endangle, /*emulateCCW=*/true); angle = (startangle + endangle)/2; } - pnt1 = arc->getCenter(); - pnt2 = pnt1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); + Base::Vector3d center = arc->getCenter(); + pnt1 = center - radius * Base::Vector3d(cos(angle),sin(angle),0.); + pnt2 = center + radius * Base::Vector3d(cos(angle),sin(angle),0.); } else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { const Part::GeomCircle *circle = static_cast(geo); @@ -5020,8 +5035,9 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer if (angle == 10) { angle = 0; } - pnt1 = circle->getCenter(); - pnt2 = pnt1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); + Base::Vector3d center = circle->getCenter(); + pnt1 = center - radius * Base::Vector3d(cos(angle),sin(angle),0.); + pnt2 = center + radius * Base::Vector3d(cos(angle),sin(angle),0.); } else break; @@ -5036,7 +5052,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer // Get display string with units hidden if so requested asciiText->string = SbString( getPresentationString(Constr).toUtf8().constData() ); - asciiText->datumtype = SoDatumLabel::RADIUS; + asciiText->datumtype = SoDatumLabel::DIAMETER; asciiText->param1 = Constr->LabelDistance; asciiText->param2 = Constr->LabelPosition; @@ -5049,6 +5065,60 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer asciiText->pnts.finishEditing(); } break; + case Radius: + { + assert(Constr->First >= -extGeoCount && Constr->First < intGeoCount); + + Base::Vector3d pnt1(0.,0.,0.), pnt2(0.,0.,0.); + if (Constr->First != Constraint::GeoUndef) { + const Part::Geometry *geo = GeoById(*geomlist, Constr->First); + + if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + const Part::GeomArcOfCircle *arc = static_cast(geo); + double radius = arc->getRadius(); + double angle = (double) Constr->LabelPosition; + if (angle == 10) { + double startangle, endangle; + arc->getRange(startangle, endangle, /*emulateCCW=*/true); + angle = (startangle + endangle)/2; + } + pnt1 = arc->getCenter(); + pnt2 = pnt1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); + } + else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { + const Part::GeomCircle *circle = static_cast(geo); + double radius = circle->getRadius(); + double angle = (double) Constr->LabelPosition; + if (angle == 10) { + angle = 0; + } + pnt1 = circle->getCenter(); + pnt2 = pnt1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); + } + else + break; + } else + break; + + SbVec3f p1(pnt1.x,pnt1.y,zConstr); + SbVec3f p2(pnt2.x,pnt2.y,zConstr); + + SoDatumLabel *asciiText = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData()); + + asciiText->datumtype = SoDatumLabel::RADIUS; + asciiText->param1 = Constr->LabelDistance; + asciiText->param2 = Constr->LabelPosition; + + asciiText->pnts.setNum(2); + SbVec3f *verts = asciiText->pnts.startEditing(); + + verts[0] = p1; + verts[1] = p2; + + asciiText->pnts.finishEditing(); + } + break; case Coincident: // nothing to do for coincident case None: case InternalAlignment: @@ -5119,6 +5189,7 @@ void ViewProviderSketch::rebuildConstraintsVisual(void) case DistanceX: case DistanceY: case Radius: + case Diameter: case Angle: { SoDatumLabel *text = new SoDatumLabel();