From: nds Date: Mon, 29 Feb 2016 12:43:32 +0000 (+0300) Subject: Issue #1315 Middle point constraint problem X-Git-Tag: V_2.2.0~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=077c2197bae13c5a45842f12845ef0491d4905c7;p=modules%2Fshaper.git Issue #1315 Middle point constraint problem --- 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 000000000..4a7283bdb Binary files /dev/null and b/src/SketcherPrs/icons/collinear.png differ diff --git a/src/SketcherPrs/icons/middlepoint.png b/src/SketcherPrs/icons/middlepoint.png new file mode 100755 index 000000000..c0040d3a0 Binary files /dev/null and b/src/SketcherPrs/icons/middlepoint.png differ