From: vsv Date: Thu, 12 Mar 2015 16:22:10 +0000 (+0300) Subject: Perpendicular constraint presentation created X-Git-Tag: V_1.1.0~138^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac584092a432772acf86934ffd6c632f7e992b09;p=modules%2Fshaper.git Perpendicular constraint presentation created --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index afaae6c00..5e9cc9fe9 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -43,11 +43,6 @@ class SketchPlugin_ConstraintParallel : public SketchPlugin_ConstraintBase /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - /// Moves the feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - //SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); - /// \brief Use plugin manager for features creation SketchPlugin_ConstraintParallel(); }; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index ca791d55f..152fabe22 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include #include #include @@ -39,55 +41,10 @@ AISObjectPtr SketchPlugin_ConstraintPerpendicular::getAISObject(AISObjectPtr the if (!sketch()) return thePrevious; - std::shared_ptr aData = data(); - std::shared_ptr anAttr1 = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - std::shared_ptr anAttr2 = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); - if (!anAttr1 || !anAttr1->isObject() || !anAttr2 || !anAttr2->isObject()) - return thePrevious; - - FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object()); - if (!aFeature) - return thePrevious; - std::shared_ptr aLine1Feature = - std::dynamic_pointer_cast(aFeature); - - aFeature = ModelAPI_Feature::feature(anAttr2->object()); - if (!aFeature) - return thePrevious; - std::shared_ptr aLine2Feature = - std::dynamic_pointer_cast(aFeature); - - if (!aLine1Feature || !aLine2Feature) - return thePrevious; - - std::shared_ptr aPlane = sketch()->plane(); - std::shared_ptr aLine1, aLine2; - std::shared_ptr aConst1 = std::dynamic_pointer_cast< - ModelAPI_ResultConstruction>(anAttr1->object()); - if (aConst1) - aLine1 = aConst1->shape(); - std::shared_ptr aConst2 = std::dynamic_pointer_cast< - ModelAPI_ResultConstruction>(anAttr2->object()); - if (aConst2) - aLine2 = aConst2->shape(); - AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - anAIS->createPerpendicular(aLine1, aLine2, aPlane); - - // Set color from preferences - std::vector aRGB = Config_PropManager::color("Visualization", "sketch_constraint_color", - SKETCH_CONSTRAINT_COLOR); - anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); + if (!anAIS) { + anAIS = SketcherPrs_Factory::perpendicularConstraint(this, sketch()->coordinatePlane()); + } return anAIS; } -void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY) -{ - //Flyout point of the constraint follows it's features - return; -} - diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index fa5eaacec..3dc6f589b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -43,11 +43,6 @@ class SketchPlugin_ConstraintPerpendicular : public SketchPlugin_ConstraintBase /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - /// Moves the feature - /// \param theDeltaX the delta for X coordinate is moved - /// \param theDeltaY the delta for Y coordinate is moved - SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); - /// \brief Use plugin manager for features creation SketchPlugin_ConstraintPerpendicular(); }; diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index fcb8889ad..833e0de69 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -4,15 +4,17 @@ SET(PROJECT_HEADERS SketcherPrs.h SketcherPrs_Coincident.h SketcherPrs_Factory.h - SketcherPrs_Parallel.h - SketcherPrs_Tools.h + SketcherPrs_Parallel.h + SketcherPrs_Tools.h + SketcherPrs_Perpendicular.h ) SET(PROJECT_SOURCES SketcherPrs_Coincident.cpp SketcherPrs_Factory.cpp - SketcherPrs_Parallel.cpp - SketcherPrs_Tools.cpp + SketcherPrs_Parallel.cpp + SketcherPrs_Tools.cpp + SketcherPrs_Perpendicular.cpp ) SET(PROJECT_LIBRARIES @@ -28,6 +30,7 @@ SET(PROJECT_LIBRARIES SET(PROJECT_PICTURES icons/parallel.png + icons/perpendicular.png ) ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS}) diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index 829052fee..1e3e7c67b 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -8,6 +8,7 @@ #include #include +#include AISObjectPtr SketcherPrs_Factory::coincidentConstraint(SketchPlugin_Constraint* theConstraint, @@ -27,4 +28,13 @@ AISObjectPtr SketcherPrs_Factory::parallelConstraint(SketchPlugin_Constraint* th Handle(SketcherPrs_Parallel) aPrs = new SketcherPrs_Parallel(theConstraint, thePlane); aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); return aAISObj; -} \ No newline at end of file +} + +AISObjectPtr SketcherPrs_Factory::perpendicularConstraint(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) +{ + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_Perpendicular) aPrs = new SketcherPrs_Perpendicular(theConstraint, thePlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + return aAISObj; +} diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h index 75a496f80..fb287c05e 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.h +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -31,6 +31,12 @@ public: /// \param thePlane the current sketch plane static AISObjectPtr parallelConstraint(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane); + + /// Creates coincedent perpendicular presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + static AISObjectPtr perpendicularConstraint(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); }; #endif diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index ed23fc519..9cb425b46 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -35,45 +34,26 @@ extern std::shared_ptr getFeaturePoint(DataPtr theData, const std::string& theAttribute); -#ifdef WIN32 -# define FSEP "\\" -#else -# define FSEP "/" -#endif - -IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject); -IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject); +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, SketcherPrs_SymbolPrs); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, SketcherPrs_SymbolPrs); static Handle(Image_AlienPixMap) MyPixMap; SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane) - : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane) + : SketcherPrs_SymbolPrs(theConstraint, thePlane) { - if (MyPixMap.IsNull()) { - TCollection_AsciiString aFile(getenv("NewGeomResources")); - aFile += FSEP; - aFile += "parallel.png"; - MyPixMap = new Image_AlienPixMap(); - if (!MyPixMap->Load(aFile)) - MyPixMap.Nullify(); - } - if (!MyPixMap.IsNull()) { - myAspect = new Graphic3d_AspectMarker3d(MyPixMap); - myPntArray = new Graphic3d_ArrayOfPoints(2); - myPntArray->AddVertex(0., 0., 0.); - myPntArray->AddVertex(0. ,0., 0.); - } - SetAutoHilight(Standard_False); + myPntArray = new Graphic3d_ArrayOfPoints(2); + myPntArray->AddVertex(0., 0., 0.); + myPntArray->AddVertex(0. ,0., 0.); } void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { - if (myAspect.IsNull()) - return; + prepareAspect(); std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (aLine1.get() == NULL) @@ -102,7 +82,7 @@ void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& t (aPnt1->z() + aPnt2->z())/2.); gp_Vec aVec2(aPnt1->impl(), aPnt2->impl()); - aShift = aVec1.Crossed(myPlane->norm()->impl()); + aShift = aVec2.Crossed(myPlane->norm()->impl()); aShift.Normalize(); aShift.Multiply(20); aP2.Translate(aShift); @@ -118,13 +98,6 @@ void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& a const Standard_Integer aMode) { ClearSelected(); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - if (aLine1.get() == NULL) - return; - - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (aLine2.get() == NULL) - return; Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this); Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1)); @@ -162,38 +135,12 @@ void SketcherPrs_Parallel::HilightOwnerWithColor(const Handle(PrsMgr_Presentatio void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const { - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - if (aLine1.get() == NULL) - return; - - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (aLine2.get() == NULL) - return; - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); aGroup->SetPrimitivesAspect(aLineAspect); - std::shared_ptr aPnt1 = aLine1->firstPoint(); - std::shared_ptr aPnt2 = aLine1->lastPoint(); - Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1); - aLines->AddVertex(aPnt1->impl()); - aLines->AddVertex(aPnt2->impl()); - aGroup->AddPrimitiveArray(aLines); - - aPnt1 = aLine2->firstPoint(); - aPnt2 = aLine2->lastPoint(); - aLines = new Graphic3d_ArrayOfSegments(2, 1); - aLines->AddVertex(aPnt1->impl()); - aLines->AddVertex(aPnt2->impl()); - aGroup->AddPrimitiveArray(aLines); + addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); + addLine(aGroup, SketchPlugin_Constraint::ENTITY_B()); } -void SketcherPrs_Parallel::ClearSelected() -{ - Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL ); - if( !aSelectionPrs.IsNull() ) { - aSelectionPrs->Clear(); - } -} diff --git a/src/SketcherPrs/SketcherPrs_Parallel.h b/src/SketcherPrs/SketcherPrs_Parallel.h index 5ead01c60..9ea829874 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.h +++ b/src/SketcherPrs/SketcherPrs_Parallel.h @@ -7,30 +7,25 @@ #ifndef SketcherPrs_Parallel_H #define SketcherPrs_Parallel_H -#include -#include - -#include -#include -#include -#include +#include "SketcherPrs_SymbolPrs.h" class SketchPlugin_Constraint; class SketchPlugin_Sketch; -DEFINE_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject) +DEFINE_STANDARD_HANDLE(SketcherPrs_Parallel, SketcherPrs_SymbolPrs) /** * \ingroup GUI * A redefinition of standard AIS Interactive Object in order to provide -* presentation of coincident constraint +* presentation of parallel constraint */ -class SketcherPrs_Parallel: public AIS_InteractiveObject +class SketcherPrs_Parallel: public SketcherPrs_SymbolPrs { public: /// Constructor - /// \param theResult a result object + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch Standard_EXPORT SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane); @@ -43,10 +38,6 @@ public: Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner); - //! Method which clear all selected owners belonging - //! to this selectable object ( for fast presentation draw ) - Standard_EXPORT virtual void ClearSelected(); - DEFINE_STANDARD_RTTI(SketcherPrs_Parallel) protected: /// Redefinition of virtual function @@ -57,13 +48,12 @@ protected: Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) ; + virtual const char* iconName() const { return "parallel.png"; } + private: void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; - SketchPlugin_Constraint* myConstraint; - std::shared_ptr myPlane; - Handle(Graphic3d_AspectMarker3d) myAspect; Handle(Graphic3d_ArrayOfPoints) myPntArray; }; diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp new file mode 100644 index 000000000..1d20021b3 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -0,0 +1,148 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Perpendicular.cpp +// Created: 12 March 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Perpendicular.h" +#include "SketcherPrs_Tools.h" + +#include + +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + + +// Function which is defined in SketchPlugin_ConstraintDistance.cpp +extern std::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute); + + + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs); + +static Handle(Image_AlienPixMap) MyPixMap; + +SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* 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.); +} + +void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + prepareAspect(); + + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + if (aLine1.get() == NULL) + return; + + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + if (aLine2.get() == NULL) + return; + + std::shared_ptr aPnt1 = aLine1->firstPoint(); + std::shared_ptr aPnt2 = aLine1->lastPoint(); + gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2., + (aPnt1->y() + aPnt2->y())/2., + (aPnt1->z() + aPnt2->z())/2.); + + gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); + gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl()); + aShift.Normalize(); + aShift.Multiply(20); + aP1.Translate(aShift); + + aPnt1 = aLine2->firstPoint(); + aPnt2 = aLine2->lastPoint(); + gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2., + (aPnt1->y() + aPnt2->y())/2., + (aPnt1->z() + aPnt2->z())/2.); + + gp_Vec aVec2(aPnt1->impl(), aPnt2->impl()); + aShift = aVec2.Crossed(myPlane->norm()->impl()); + aShift.Normalize(); + aShift.Multiply(20); + aP2.Translate(aShift); + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); + aGroup->SetPrimitivesAspect(myAspect); + myPntArray->SetVertice(1, aP1); + myPntArray->SetVertice(2, aP2); + aGroup->AddPrimitiveArray(myPntArray); +} + +void SketcherPrs_Perpendicular::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) +{ + ClearSelected(); + + Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this); + Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1)); + Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2)); + aSelection->Add(aSP1); + aSelection->Add(aSP2); +} + +void SketcherPrs_Perpendicular::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, + const SelectMgr_SequenceOfOwner& theOwners) +{ + + Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM ); + aSelectionPrs->Clear(); + drawLines(aSelectionPrs, Quantity_NOC_WHITE); + + aSelectionPrs->SetDisplayPriority(9); + aSelectionPrs->Display(); + thePM->Highlight(this); +} + +void SketcherPrs_Perpendicular::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, + const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner) +{ + thePM->Color(this, theColor); + + Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM ); + aHilightPrs->Clear(); + drawLines(aHilightPrs, theColor); + + if (thePM->IsImmediateModeOn()) + thePM->AddToImmediateList(aHilightPrs); +} + + +void SketcherPrs_Perpendicular::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); + + addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); + addLine(aGroup, SketchPlugin_Constraint::ENTITY_B()); +} + diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.h b/src/SketcherPrs/SketcherPrs_Perpendicular.h new file mode 100644 index 000000000..a41350b4e --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.h @@ -0,0 +1,60 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Perpendicular.h +// Created: 12 March 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_Perpendicular_H +#define SketcherPrs_Perpendicular_H + +#include "SketcherPrs_SymbolPrs.h" + +class SketchPlugin_Sketch; + + +DEFINE_STANDARD_HANDLE(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide +* presentation of perpendicular constraint +*/ +class SketcherPrs_Perpendicular: public SketcherPrs_SymbolPrs +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + Standard_EXPORT SketcherPrs_Perpendicular(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + //! Method which draws selected owners ( for fast presentation draw ) + Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, + const SelectMgr_SequenceOfOwner& theOwners); + + //! Method which hilight an owner belonging to + //! this selectable object ( for fast presentation draw ) + Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, + const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner); + + + DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular) +protected: + /// Redefinition of virtual function + Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); + + /// Redefinition of virtual function + Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) ; + + virtual const char* iconName() const { return "perpendicular.png"; } + +private: + + void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const; + + Handle(Graphic3d_ArrayOfPoints) myPntArray; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp new file mode 100644 index 000000000..144664122 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -0,0 +1,79 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_SymbolPrs.cpp +// Created: 12 March 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_SymbolPrs.h" +#include "SketcherPrs_Tools.h" + +#include + +#include + + +#ifdef WIN32 +# define FSEP "\\" +#else +# define FSEP "/" +#endif + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject); + + +std::map SketcherPrs_SymbolPrs::myIconsMap; + + +SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) + : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane) +{ + SetAutoHilight(Standard_False); +} + +Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon() +{ + if (myIconsMap.count(iconName()) == 1) { + return myIconsMap[iconName()]; + } + TCollection_AsciiString aFile(getenv("NewGeomResources")); + aFile += FSEP; + aFile += iconName(); + Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap(); + if (aPixMap->Load(aFile)) { + myIconsMap[iconName()] = aPixMap; + return aPixMap; + } + return Handle(Image_AlienPixMap)(); +} + +void SketcherPrs_SymbolPrs::ClearSelected() +{ + Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL ); + if( !aSelectionPrs.IsNull() ) { + aSelectionPrs->Clear(); + } +} + +void SketcherPrs_SymbolPrs::prepareAspect() +{ + if (myAspect.IsNull()) { + myAspect = new Graphic3d_AspectMarker3d(icon()); + } +} + +void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const +{ + std::shared_ptr aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName); + if (aLine.get() == NULL) + return; + + std::shared_ptr aPnt1 = aLine->firstPoint(); + std::shared_ptr aPnt2 = aLine->lastPoint(); + + Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1); + aLines->AddVertex(aPnt1->impl()); + aLines->AddVertex(aPnt2->impl()); + theGroup->AddPrimitiveArray(aLines); +} diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h new file mode 100644 index 000000000..792fde015 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -0,0 +1,74 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_SymbolPrs.h +// Created: 12 March 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_SymbolPrs_H +#define SketcherPrs_SymbolPrs_H + +#include +#include +#include +#include +#include + +#include +#include + +class SketchPlugin_Constraint; + + +DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject) + +/** +* \ingroup GUI +* A base class of constraint presentation which is represented by an icon +*/ +class SketcherPrs_SymbolPrs: public AIS_InteractiveObject +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + //! Method which clear all selected owners belonging + //! to this selectable object ( for fast presentation draw ) + Standard_EXPORT virtual void ClearSelected(); + + DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs) + +protected: + /// Returns an icon file name. Has to be redefined in successors + virtual const char* iconName() const = 0; + + /// Check and creates if it is necessary myAspect member. + /// It has to be called before the object computation + virtual void prepareAspect(); + + /// Returns icon corresponded to the current constraint type + Handle(Image_AlienPixMap) icon(); + + /// Add a line into the given group + /// \param theGroup a group for drawing + /// \param theAttrName an attribute name which corresponds to referenced line + void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const; + +protected: + /// Constraint feature + SketchPlugin_Constraint* myConstraint; + + /// Plane of the current sketcher + std::shared_ptr myPlane; + + /// Aspect for entities drawing + Handle(Graphic3d_AspectMarker3d) myAspect; + +private: + /// Static map to collect constraints icons {IconName : IconPixMap} + static std::map myIconsMap; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/icons/perpendicular.png b/src/SketcherPrs/icons/perpendicular.png new file mode 100644 index 000000000..8f64a9f82 Binary files /dev/null and b/src/SketcherPrs/icons/perpendicular.png differ