From: vsv Date: Tue, 23 Jun 2020 07:21:11 +0000 (+0300) Subject: Issue #3231: Provide presentation for offset operation X-Git-Tag: V9_6_0a1~60^2~54 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b77c6a3e1a77c0d1c9484e566927f24ec6152b27;p=modules%2Fshaper.git Issue #3231: Provide presentation for offset operation --- diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp index f941bc315..0183cec9b 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.cpp +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -484,3 +486,14 @@ bool SketchPlugin_Offset::findWires() return true; } + + +AISObjectPtr SketchPlugin_Offset::getAISObject(AISObjectPtr thePrevious) +{ + if (!sketch()) + return thePrevious; + + AISObjectPtr anAIS = SketcherPrs_Factory::offsetObject(this, sketch(), + thePrevious); + return anAIS; +} diff --git a/src/SketchPlugin/SketchPlugin_Offset.h b/src/SketchPlugin/SketchPlugin_Offset.h index af74b7169..7ed4e3794 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.h +++ b/src/SketchPlugin/SketchPlugin_Offset.h @@ -24,13 +24,15 @@ #include #include + #include +#include /**\class SketchPlugin_Offset * \ingroup Plugins * \brief Builds offset curves in the sketch. */ -class SketchPlugin_Offset : public SketchPlugin_SketchEntity +class SketchPlugin_Offset : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable { public: /// Offset macro feature kind @@ -83,7 +85,7 @@ public: /// Reimplemented from ModelAPI_Feature::isMacro(). /// \returns true - SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; } + //SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return false; } //SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; } SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return true; } @@ -95,6 +97,9 @@ public: /// \return \c false in case the action not performed. SKETCHPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId); + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// Use plugin manager for features creation. SketchPlugin_Offset(); diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 51a7b9f8b..8941eb5c8 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -44,6 +44,7 @@ SET(PROJECT_HEADERS SketcherPrs_Mirror.h SketcherPrs_Transformation.h SketcherPrs_Angle.h + SketcherPrs_Offset.h ) SET(PROJECT_SOURCES @@ -67,6 +68,7 @@ SET(PROJECT_SOURCES SketcherPrs_Mirror.cpp SketcherPrs_Transformation.cpp SketcherPrs_Angle.cpp + SketcherPrs_Offset.cpp ) SET(PROJECT_LIBRARIES @@ -102,6 +104,7 @@ SET(PROJECT_PICTURES icons/mirror.png icons/rotate.png icons/translate.png + icons/offset.png ) ADD_DEFINITIONS(-DSKETCHERPRS_EXPORTS ${OpenCASCADE_DEFINITIONS} -D_CRT_SECURE_NO_WARNINGS) diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index 553ea9cf9..d9ed485f4 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -33,6 +33,7 @@ #include "SketcherPrs_Mirror.h" #include "SketcherPrs_Transformation.h" #include "SketcherPrs_Angle.h" +#include "SketcherPrs_Offset.h" // Macros for constraint presentation definition #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \ @@ -66,6 +67,7 @@ CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident); CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension); CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle); CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius); +CONSTRAINT_PRS_IMPL(offsetObject, SketcherPrs_Offset); // Non-standard constraints definition AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint, diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h index 6d324d43c..bc664eebe 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.h +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -135,6 +135,12 @@ public: /// \param thePlane the current sketch plane /// \param thePrevious the previous presentation GET_CONSTRAINT_PRS(radiusConstraint) + + /// Creates radius dimension presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + /// \param thePrevious the previous presentation + GET_CONSTRAINT_PRS(offsetObject) }; #endif diff --git a/src/SketcherPrs/SketcherPrs_Offset.cpp b/src/SketcherPrs/SketcherPrs_Offset.cpp new file mode 100644 index 000000000..c90f2d404 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Offset.cpp @@ -0,0 +1,100 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "SketcherPrs_Offset.h" +#include "SketcherPrs_Tools.h" +#include "SketcherPrs_PositionMgr.h" + +#include + +#include +#include + +#include +#include + + +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Offset, SketcherPrs_SymbolPrs); + +static Handle(Image_AlienPixMap) MyPixMap; + +SketcherPrs_Offset::SketcherPrs_Offset(ModelAPI_Feature* theConstraint, + SketchPlugin_Sketch* theSketcher) + : SketcherPrs_SymbolPrs(theConstraint, theSketcher) +{ +} + +bool SketcherPrs_Offset::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + AttributeDoublePtr aValueAttr = theConstraint->real(SketchPlugin_Offset::VALUE_ID()); + if (aValueAttr->isInitialized()) { + AttributeRefListPtr aSelectedEdges = theConstraint->reflist(SketchPlugin_Offset::EDGES_ID()); + aReadyToDisplay = (aSelectedEdges->list().size() > 0); + } + return aReadyToDisplay; +} + +bool SketcherPrs_Offset::updateIfReadyToDisplay(double theStep, bool withColor) const +{ + if (!IsReadyToDisplay(myConstraint, plane())) + return false; + if (!plane()) + return false; + + // Set points of the presentation + SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); + + AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::EDGES_ID()); + int aNb = aSelectedEdges->size(); + + //std::list > aResList = myConstraint->results(); + //int aRNb = aResList.size(); + + myPntArray = new Graphic3d_ArrayOfPoints(aNb, withColor); + int i; + ObjectPtr aObj; + gp_Pnt aP1; + // get position for each source object + for (i = 0; i < aNb; i++) { + aObj = aSelectedEdges->object(i); + if (SketcherPrs_Tools::getShape(aObj).get() == NULL) + continue; + aP1 = aMgr->getPosition(aObj, this, theStep); + myPntArray->SetVertice(i + 1, aP1); + } + return true; +} + +void SketcherPrs_Offset::drawLines(const Handle(Prs3d_Presentation)& thePrs, + Quantity_Color theColor) const +{ + AttributeRefListPtr aSelectedEdges = myConstraint->reflist(SketchPlugin_Offset::EDGES_ID()); + if (aSelectedEdges.get() == NULL) + return; + + int aNb = aSelectedEdges->size(); + if (aNb == 0) + return; + + // Draw source objects + drawListOfShapes(aSelectedEdges, thePrs, theColor); +} diff --git a/src/SketcherPrs/SketcherPrs_Offset.h b/src/SketcherPrs/SketcherPrs_Offset.h new file mode 100644 index 000000000..b890317b8 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Offset.h @@ -0,0 +1,60 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SketcherPrs_Offset_H +#define SketcherPrs_Offset_H + +#include "SketcherPrs_SymbolPrs.h" + + +DEFINE_STANDARD_HANDLE(SketcherPrs_Offset, SketcherPrs_SymbolPrs) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide +* presentation of Equal constraint +*/ +class SketcherPrs_Offset : public SketcherPrs_SymbolPrs +{ +public: + /// Constructor + /// \param theConstraint a constraint feature + /// \param theSketcher a sketcher object + Standard_EXPORT SketcherPrs_Offset(ModelAPI_Feature* theConstraint, + SketchPlugin_Sketch* theSketcher); + DEFINE_STANDARD_RTTIEXT(SketcherPrs_Offset, SketcherPrs_SymbolPrs) + + /// 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 "offset.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 updateIfReadyToDisplay(double theStep, bool withColor) const; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/icons/offset.png b/src/SketcherPrs/icons/offset.png new file mode 100644 index 000000000..0e0f73786 Binary files /dev/null and b/src/SketcherPrs/icons/offset.png differ