Salome HOME
Issue #3231: Provide presentation for offset operation
authorvsv <vsv@opencascade.com>
Tue, 23 Jun 2020 07:21:11 +0000 (10:21 +0300)
committervsv <vsv@opencascade.com>
Tue, 23 Jun 2020 07:21:26 +0000 (10:21 +0300)
src/SketchPlugin/SketchPlugin_Offset.cpp
src/SketchPlugin/SketchPlugin_Offset.h
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_Factory.cpp
src/SketcherPrs/SketcherPrs_Factory.h
src/SketcherPrs/SketcherPrs_Offset.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Offset.h [new file with mode: 0644]
src/SketcherPrs/icons/offset.png [new file with mode: 0644]

index f941bc315dd73c5d85d895d1b0f569fcbc724873..0183cec9b6740ca898fef1a64dad48ee2bf92e18 100644 (file)
@@ -30,6 +30,8 @@
 #include <SketchPlugin_BSplinePeriodic.h>
 #include <SketchPlugin_Tools.h>
 
+#include <SketcherPrs_Factory.h>
+
 #include <Events_InfoMessage.h>
 
 #include <ModelAPI_AttributeBoolean.h>
@@ -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;
+}
index af74b7169659ee2066f4c12c6ed6e902458d1f9d..7ed4e379494fdbe3a0bb66c793f0a7da8d45c202 100644 (file)
 #include <SketchPlugin_SketchEntity.h>
 
 #include <GeomDataAPI_Point2D.h>
+
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_IPresentable.h>
 
 /**\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();
 
index 51a7b9f8be1b09954e5ed83fe2e5070ac06bc586..8941eb5c8580fc69a1868fd306e9762ba46a6a83 100644 (file)
@@ -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)
index 553ea9cf95011c965d13048ee4bc2989cb0fbbaa..d9ed485f4ecfeb63362b6e36b48abfd43ab8ac6c 100644 (file)
@@ -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,
index 6d324d43c8a49fb8932b59a81b87f42d741829ad..bc664eebee3242ea4f9dca9acd3fec9b4c369504 100644 (file)
@@ -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 (file)
index 0000000..c90f2d4
--- /dev/null
@@ -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 <SketchPlugin_Offset.h>
+
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Prs3d_Root.hxx>
+
+
+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<GeomAPI_Ax3>&/* 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<std::shared_ptr<ModelAPI_Result> > 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 (file)
index 0000000..b890317
--- /dev/null
@@ -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<GeomAPI_Ax3>& 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 (file)
index 0000000..0e0f737
Binary files /dev/null and b/src/SketcherPrs/icons/offset.png differ