From 077c2197bae13c5a45842f12845ef0491d4905c7 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 29 Feb 2016 15:43:32 +0300 Subject: [PATCH] Issue #1315 Middle point constraint problem --- .../SketchPlugin_ConstraintCollinear.cpp | 8 +- .../SketchPlugin_ConstraintMiddle.cpp | 8 +- .../SketchPlugin_ConstraintMiddle.h | 2 +- src/SketcherPrs/CMakeLists.txt | 2 + src/SketcherPrs/SketcherPrs_Collinear.cpp | 16 +--- src/SketcherPrs/SketcherPrs_Collinear.h | 4 +- src/SketcherPrs/SketcherPrs_Factory.cpp | 4 + src/SketcherPrs/SketcherPrs_Factory.h | 10 +++ src/SketcherPrs/SketcherPrs_Middle.cpp | 72 ++++++++++++------ src/SketcherPrs/SketcherPrs_Middle.h | 6 +- src/SketcherPrs/SketcherPrs_Tools.cpp | 7 ++ src/SketcherPrs/SketcherPrs_Tools.h | 7 ++ src/SketcherPrs/icons/collinear.png | Bin 0 -> 409 bytes src/SketcherPrs/icons/middlepoint.png | Bin 0 -> 247 bytes 14 files changed, 99 insertions(+), 47 deletions(-) create mode 100755 src/SketcherPrs/icons/collinear.png create mode 100755 src/SketcherPrs/icons/middlepoint.png diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp index d7c7e07c3..6e175a9d3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp @@ -6,6 +6,8 @@ #include "SketchPlugin_ConstraintCollinear.h" +#include "SketcherPrs_Factory.h" + SketchPlugin_ConstraintCollinear::SketchPlugin_ConstraintCollinear() { } @@ -25,10 +27,8 @@ AISObjectPtr SketchPlugin_ConstraintCollinear::getAISObject(AISObjectPtr thePrev if (!sketch()) return thePrevious; - AISObjectPtr anAIS; - // TODO - //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(), - // thePrevious); + AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp index 7112d4401..31fc3f1da 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp @@ -6,6 +6,8 @@ #include "SketchPlugin_ConstraintMiddle.h" +#include "SketcherPrs_Factory.h" + SketchPlugin_ConstraintMiddle::SketchPlugin_ConstraintMiddle() { } @@ -25,10 +27,8 @@ AISObjectPtr SketchPlugin_ConstraintMiddle::getAISObject(AISObjectPtr thePreviou if (!sketch()) return thePrevious; - AISObjectPtr anAIS; - // TODO - //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(), - // thePrevious); + AISObjectPtr anAIS = SketcherPrs_Factory::middleConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h index 9cf7b866f..148942a5b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h @@ -13,7 +13,7 @@ /** \class SketchPlugin_ConstraintMiddle * \ingroup Plugins - * \brief Feature for creation of a new constraintwhich places a point in the middle of a line + * \brief Feature for creation of a new constraint which places a point in the middle of a line * * This constraint has two attributes: * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 221e5a1b3..55d73ee50 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -73,6 +73,7 @@ ENDIF() SET(PROJECT_PICTURES + icons/collinear.png icons/parallel.png icons/perpendicular.png icons/anchor.png @@ -80,6 +81,7 @@ SET(PROJECT_PICTURES icons/vertical.png icons/equal.png icons/tangent.png + icons/middlepoint.png icons/mirror.png icons/rotate.png icons/translate.png diff --git a/src/SketcherPrs/SketcherPrs_Collinear.cpp b/src/SketcherPrs/SketcherPrs_Collinear.cpp index 57cf26413..64e027394 100755 --- a/src/SketcherPrs/SketcherPrs_Collinear.cpp +++ b/src/SketcherPrs/SketcherPrs_Collinear.cpp @@ -68,18 +68,8 @@ void SketcherPrs_Collinear::drawLines(const Handle(Prs3d_Presentation)& thePrs, Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); - // Draw first line - ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aLine = SketcherPrs_Tools::getShape(aObj); - if (aLine.get() == NULL) - return; - drawShape(aLine, thePrs); - - // Draw second line - aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - aLine = SketcherPrs_Tools::getShape(aObj); - if (aLine.get() == NULL) - return; - drawShape(aLine, thePrs); + // Draw constrained lines + addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); + addLine(aGroup, SketchPlugin_Constraint::ENTITY_B()); } diff --git a/src/SketcherPrs/SketcherPrs_Collinear.h b/src/SketcherPrs/SketcherPrs_Collinear.h index e48065cd6..e43fdac89 100755 --- a/src/SketcherPrs/SketcherPrs_Collinear.h +++ b/src/SketcherPrs/SketcherPrs_Collinear.h @@ -1,7 +1,7 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: SketcherPrs_Collinear.h -// Created: 29 February 2016 +// Created: 29 Feb 2016 // Author: Natalia ERMOLAEVA #ifndef SketcherPrs_Collinear_H @@ -35,7 +35,7 @@ public: const std::shared_ptr& thePlane); protected: - virtual const char* iconName() const { return "equal.png"; } + virtual const char* iconName() const { return "collinear.png"; } virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index 9ab167332..449c3c24a 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -7,6 +7,7 @@ #include "SketcherPrs_Factory.h" #include "SketcherPrs_Coincident.h" +#include "SketcherPrs_Collinear.h" #include "SketcherPrs_Parallel.h" #include "SketcherPrs_Perpendicular.h" #include "SketcherPrs_Rigid.h" @@ -15,6 +16,7 @@ #include "SketcherPrs_Tangent.h" #include "SketcherPrs_Radius.h" #include "SketcherPrs_LengthDimension.h" +#include "SketcherPrs_Middle.h" #include "SketcherPrs_Mirror.h" #include "SketcherPrs_Transformation.h" #include "SketcherPrs_Angle.h" @@ -39,6 +41,7 @@ AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \ } CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident); +CONSTRAINT_PRS_IMPL(collinearConstraint, SketcherPrs_Collinear); CONSTRAINT_PRS_IMPL(parallelConstraint, SketcherPrs_Parallel); CONSTRAINT_PRS_IMPL(perpendicularConstraint, SketcherPrs_Perpendicular); CONSTRAINT_PRS_IMPL(rigidConstraint, SketcherPrs_Rigid); @@ -46,6 +49,7 @@ CONSTRAINT_PRS_IMPL(equalConstraint, SketcherPrs_Equal); CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent); CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius); CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension); +CONSTRAINT_PRS_IMPL(middleConstraint, SketcherPrs_Middle); CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror); CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle); diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h index 485c5a6fe..2f43622b0 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.h +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -30,6 +30,11 @@ public: /// \param thePlane the current sketch plane GET_CONSTRAINT_PRS(coincidentConstraint) + /// Creates collinear constraint presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + GET_CONSTRAINT_PRS(collinearConstraint) + /// Creates parallel constraint presentation /// \param theConstraint the constraint /// \param thePlane the current sketch plane @@ -75,6 +80,11 @@ public: /// \param thePlane the current sketch plane GET_CONSTRAINT_PRS(lengthDimensionConstraint) + /// Creates middle constraint presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + GET_CONSTRAINT_PRS(middleConstraint) + /// Creates mirror constraint presentation /// \param theConstraint the constraint /// \param thePlane the current sketch plane diff --git a/src/SketcherPrs/SketcherPrs_Middle.cpp b/src/SketcherPrs/SketcherPrs_Middle.cpp index a588752a7..eaba71733 100755 --- a/src/SketcherPrs/SketcherPrs_Middle.cpp +++ b/src/SketcherPrs/SketcherPrs_Middle.cpp @@ -27,7 +27,6 @@ SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint, { myPntArray = new Graphic3d_ArrayOfPoints(2); myPntArray->AddVertex(0., 0., 0.); - myPntArray->AddVertex(0., 0., 0.); } bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, @@ -38,8 +37,10 @@ bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B()); - aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL && - SketcherPrs_Tools::getShape(aObj2).get() != NULL; + // one object is a feature Line, other object is a point result. We check shape of point result + aReadyToDisplay = aObj1.get() && aObj2.get() && + (SketcherPrs_Tools::getShape(aObj1).get() != NULL || + SketcherPrs_Tools::getShape(aObj2).get() != NULL); return aReadyToDisplay; } @@ -48,16 +49,30 @@ bool SketcherPrs_Middle::updatePoints(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; - - ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + ObjectPtr aPointObject; + + // find a line result to set middle symbol near it + AttributePtr anAttribute = SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + if (!anAttribute.get()) { + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr aShape = SketcherPrs_Tools::getShape(aObj); + if (aShape.get() && aShape->isEdge()) + aPointObject = aObj; + } + if (!aPointObject.get()) { + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + std::shared_ptr aShape = SketcherPrs_Tools::getShape(aObj); + if (aShape.get() && aShape->isEdge()) + aPointObject = aObj; + } + + if (!aPointObject.get()) + return false; // Set points of the presentation SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep); - gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); + gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep); myPntArray->SetVertice(1, aP1); - myPntArray->SetVertice(2, aP2); return true; } @@ -68,18 +83,31 @@ void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, Qua Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); - // Draw first line - ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aLine = SketcherPrs_Tools::getShape(aObj); - if (aLine.get() == NULL) - return; - drawShape(aLine, thePrs); - - // Draw second line - aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - aLine = SketcherPrs_Tools::getShape(aObj); - if (aLine.get() == NULL) - return; - drawShape(aLine, thePrs); + // Draw objects + ObjectPtr aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + drawLine(thePrs, theColor, aObject); + + aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + drawLine(thePrs, theColor, aObject); +} + +void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs, + Quantity_Color theColor, const ObjectPtr& theObject) const +{ + FeaturePtr aLineFeature = std::dynamic_pointer_cast(theObject); + if (aLineFeature.get()) { + std::list aResults = aLineFeature->results(); + if (aResults.size() == 1) { + ResultPtr aResult = aResults.front(); + std::shared_ptr aLine = SketcherPrs_Tools::getShape(aResult); + if (aLine.get() != NULL) + drawShape(aLine, thePrs); + } + } + else { + std::shared_ptr aLine = SketcherPrs_Tools::getShape(theObject); + if (aLine.get() != NULL) + drawShape(aLine, thePrs); + } } diff --git a/src/SketcherPrs/SketcherPrs_Middle.h b/src/SketcherPrs/SketcherPrs_Middle.h index fb72cec29..10d22ba86 100755 --- a/src/SketcherPrs/SketcherPrs_Middle.h +++ b/src/SketcherPrs/SketcherPrs_Middle.h @@ -35,13 +35,17 @@ public: const std::shared_ptr& thePlane); protected: - virtual const char* iconName() const { return "equal.png"; } + virtual const char* iconName() const { return "middlepoint.png"; } virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; /// Update myPntArray according to presentation positions /// \return true in case of success virtual bool updatePoints(double theStep) const; + + /// Draw shape of the object. Find shape result if the object is feature + void drawLine(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor, + const ObjectPtr& theObject) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 78b521957..d481dcbe7 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -35,6 +35,13 @@ static const Standard_ExtCharacter MySigmaSymbol(0x03A3); namespace SketcherPrs_Tools { +AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName) +{ + std::shared_ptr aData = theFeature->data(); + std::shared_ptr anAttr = aData->refattr(theAttrName); + return !anAttr->isObject() ? anAttr->attr() : AttributePtr(); +} + ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName) { std::shared_ptr aData = theFeature->data(); diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index f490898f4..1af656aee 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,12 @@ namespace SketcherPrs_Tools { Sel_Dimension_Text }; + /// Returns attribute object referenced by feature + /// \param theFeature a feature + /// \param theAttrName an attribute name + SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature, + const std::string& theAttrName); + /// Returns result object referenced by feature /// \param theFeature a feature /// \param theAttrName an attribute name diff --git a/src/SketcherPrs/icons/collinear.png b/src/SketcherPrs/icons/collinear.png new file mode 100755 index 0000000000000000000000000000000000000000..4a7283bdb6d3e170d31190c2d36256a57c82addd GIT binary patch literal 409 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=fts&@Fyn;$$~izmsS?+SlHmNblJdl&REB`W%)AmkKi3e2GGjec zJwpS7FGUN1#&USNIEGmGCm&$j;_Q4=N=oV<^UVK}PR=tG7r8JMnwzuDc=mrk>;G;` zRtJ?1))TXi#{N-kI>MB4cG0?n0**2c$Bd>3uaG+=Sjy3w&6YTUQK3+QchLhA9*)YY zPX|rCtymY{=sDsh$i9-b(IQ!ThQ*PD6xU1V8Xb<+?~vHVIM?fy#;Zg|o@WemS)Vb8 z9x#Yd^r>rVV(Us%*H)iU#KCaXdI~3V!C3{KOATu(x9zc-(8+ut$NiXsuY;z+UXK{b zMH3_pA_GN_-Yj;#QmJU<(lGOrmd32`%0ns2?w`gi#YIOL x-2$gGOh_|m4>`-T=v|$b$E<@Ui3biaFiea&QebaV3k(wm22WQ%mvv4FO#p5Fk4XRk literal 0 HcmV?d00001 diff --git a/src/SketcherPrs/icons/middlepoint.png b/src/SketcherPrs/icons/middlepoint.png new file mode 100755 index 0000000000000000000000000000000000000000..c0040d3a0dd219957b582dc06ef1017916e32618 GIT binary patch literal 247 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=fts&@Fyn;$$~izmsS?+SlHmNblJdl&REB`W%)AmkKi3e2GGjec zJwpS7FGUN1s?t1N978Pp-}Z0hYcSw&Ilp7)&*Oi#Gt0F|-7+dEeC-{V^I(D4?D+u? zL<}-P(vmb literal 0 HcmV?d00001 -- 2.39.2