From: nds Date: Mon, 29 Feb 2016 06:04:27 +0000 (+0300) Subject: Issue #1315 Middle point constraint problem: classes creation X-Git-Tag: V_2.2.0~44 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=45bb93054f95112d5e6282f11c364ed5e23fb264;p=modules%2Fshaper.git Issue #1315 Middle point constraint problem: classes creation --- diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index e988b9a84..221e5a1b3 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -8,6 +8,7 @@ FIND_PACKAGE(Freetype REQUIRED) SET(PROJECT_HEADERS SketcherPrs.h SketcherPrs_Coincident.h + SketcherPrs_Collinear.h SketcherPrs_Factory.h SketcherPrs_Parallel.h SketcherPrs_Tools.h @@ -21,6 +22,7 @@ SET(PROJECT_HEADERS SketcherPrs_SensitivePoint.h SketcherPrs_Radius.h SketcherPrs_LengthDimension.h + SketcherPrs_Middle.h SketcherPrs_Mirror.h SketcherPrs_Transformation.h SketcherPrs_Angle.h @@ -28,6 +30,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES SketcherPrs_Coincident.cpp + SketcherPrs_Collinear.cpp SketcherPrs_Factory.cpp SketcherPrs_Parallel.cpp SketcherPrs_Tools.cpp @@ -41,6 +44,7 @@ SET(PROJECT_SOURCES SketcherPrs_SensitivePoint.cpp SketcherPrs_Radius.cpp SketcherPrs_LengthDimension.cpp + SketcherPrs_Middle.cpp SketcherPrs_Mirror.cpp SketcherPrs_Transformation.cpp SketcherPrs_Angle.cpp diff --git a/src/SketcherPrs/SketcherPrs_Collinear.cpp b/src/SketcherPrs/SketcherPrs_Collinear.cpp new file mode 100755 index 000000000..57cf26413 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Collinear.cpp @@ -0,0 +1,85 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Collinear.cpp +// Created: 29 February 2016 +// Author: Natalia ERMOLAEVA + +#include "SketcherPrs_Collinear.h" +#include "SketcherPrs_Tools.h" +#include "SketcherPrs_PositionMgr.h" + +#include + +#include "Events_Error.h" + +#include +#include + + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Collinear, SketcherPrs_SymbolPrs); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Collinear, SketcherPrs_SymbolPrs); + +static Handle(Image_AlienPixMap) MyPixMap; + +SketcherPrs_Collinear::SketcherPrs_Collinear(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) + : SketcherPrs_SymbolPrs(theConstraint, thePlane) +{ + myPntArray = new Graphic3d_ArrayOfPoints(2); + myPntArray->AddVertex(0., 0., 0.); + myPntArray->AddVertex(0., 0., 0.); +} + +bool SketcherPrs_Collinear::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + 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; + + return aReadyToDisplay; +} + +bool SketcherPrs_Collinear::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()); + + // 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); + myPntArray->SetVertice(1, aP1); + myPntArray->SetVertice(2, aP2); + return true; +} + +void SketcherPrs_Collinear::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const +{ + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(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); +} + diff --git a/src/SketcherPrs/SketcherPrs_Collinear.h b/src/SketcherPrs/SketcherPrs_Collinear.h new file mode 100755 index 000000000..e48065cd6 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Collinear.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Collinear.h +// Created: 29 February 2016 +// Author: Natalia ERMOLAEVA + +#ifndef SketcherPrs_Collinear_H +#define SketcherPrs_Collinear_H + +#include "SketcherPrs_SymbolPrs.h" + + +DEFINE_STANDARD_HANDLE(SketcherPrs_Collinear, SketcherPrs_SymbolPrs) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide +* presentation of Equal constraint +*/ +class SketcherPrs_Collinear: public SketcherPrs_SymbolPrs +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_Collinear(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); + DEFINE_STANDARD_RTTI(SketcherPrs_Collinear) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); +protected: + + virtual const char* iconName() const { return "equal.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; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Middle.cpp b/src/SketcherPrs/SketcherPrs_Middle.cpp new file mode 100755 index 000000000..a588752a7 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Middle.cpp @@ -0,0 +1,85 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Middle.cpp +// Created: 29 February 2016 +// Author: Natalia ERMOLAEVA + +#include "SketcherPrs_Middle.h" +#include "SketcherPrs_Tools.h" +#include "SketcherPrs_PositionMgr.h" + +#include + +#include "Events_Error.h" + +#include +#include + + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Middle, SketcherPrs_SymbolPrs); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Middle, SketcherPrs_SymbolPrs); + +static Handle(Image_AlienPixMap) MyPixMap; + +SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) + : SketcherPrs_SymbolPrs(theConstraint, thePlane) +{ + myPntArray = new Graphic3d_ArrayOfPoints(2); + myPntArray->AddVertex(0., 0., 0.); + myPntArray->AddVertex(0., 0., 0.); +} + +bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + 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; + + return aReadyToDisplay; +} + +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()); + + // 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); + myPntArray->SetVertice(1, aP1); + myPntArray->SetVertice(2, aP2); + return true; +} + +void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const +{ + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(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); +} + diff --git a/src/SketcherPrs/SketcherPrs_Middle.h b/src/SketcherPrs/SketcherPrs_Middle.h new file mode 100755 index 000000000..fb72cec29 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Middle.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Middle.h +// Created: 29 February 2016 +// Author: Natalia ERMOLAEVA + +#ifndef SketcherPrs_Middle_H +#define SketcherPrs_Middle_H + +#include "SketcherPrs_SymbolPrs.h" + + +DEFINE_STANDARD_HANDLE(SketcherPrs_Middle, SketcherPrs_SymbolPrs) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide +* presentation of Equal constraint +*/ +class SketcherPrs_Middle: public SketcherPrs_SymbolPrs +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_Middle(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); + DEFINE_STANDARD_RTTI(SketcherPrs_Middle) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); +protected: + + virtual const char* iconName() const { return "equal.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; +}; + +#endif \ No newline at end of file