]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Axis feature in Construction plugin is created
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Dec 2014 13:48:43 +0000 (16:48 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Dec 2014 13:48:43 +0000 (16:48 +0300)
13 files changed:
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp [new file with mode: 0644]
src/ConstructionPlugin/ConstructionPlugin_Axis.h [new file with mode: 0644]
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ConstructionPlugin/axis_widget.xml [new file with mode: 0644]
src/ConstructionPlugin/plugin-Construction.xml
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_Displayer.cpp

index b95bcb7283e019906c9ba0d86181d66b78f4d436..0ddbb7f1b42a4807c3b210520adb9dd1fbe6e4df 100644 (file)
@@ -7,16 +7,19 @@ SET(PROJECT_HEADERS
     ConstructionPlugin.h
     ConstructionPlugin_Plugin.h
     ConstructionPlugin_Point.h
+       ConstructionPlugin_Axis.h
 )
 
 SET(PROJECT_SOURCES
     ConstructionPlugin_Plugin.cpp
     ConstructionPlugin_Point.cpp
+       ConstructionPlugin_Axis.cpp
 )
 
 SET(XML_RESOURCES
   plugin-Construction.xml
   point_widget.xml
+  axis_widget.xml
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
new file mode 100644 (file)
index 0000000..de672a2
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ConstructionPlugin_Axis.cpp
+// Created:     12 Dec 2014
+// Author:      Vitaly Smetannikov
+
+#include "ConstructionPlugin_Axis.h"
+
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+
+using namespace std;
+
+static const double MINIMAL_LENGTH      = 1.e-5;
+
+ConstructionPlugin_Axis::ConstructionPlugin_Axis()
+{
+}
+
+void ConstructionPlugin_Axis::initAttributes()
+{
+  data()->addAttribute(POINT_ATTR_FIRST,  ModelAPI_AttributeReference::type());
+  data()->addAttribute(POINT_ATTR_SECOND, ModelAPI_AttributeReference::type());
+}
+
+void ConstructionPlugin_Axis::execute()
+{
+  AttributeReferencePtr aRef1 = data()->reference(POINT_ATTR_FIRST);
+  AttributeReferencePtr aRef2 = data()->reference(POINT_ATTR_SECOND);
+  if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
+    ResultConstructionPtr aPntObj1 = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRef1->value());
+    ResultConstructionPtr aPntObj2 = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRef2->value());
+    if ((aPntObj1.get() != NULL) && (aPntObj2.get() != NULL)) {
+      GeomShapePtr aShape1 = aPntObj1->shape();
+      GeomShapePtr aShape2 = aPntObj2->shape();
+      if (aShape1->isVertex() && aShape2->isVertex()) {
+        std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+        std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
+        if (aStart->distance(anEnd) > MINIMAL_LENGTH) {
+          std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+          ResultConstructionPtr aConstr = document()->createConstruction(data());
+          aConstr->setShape(anEdge);
+          setResult(aConstr);
+        }
+      }
+    }
+  }
+}
+
+void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+{
+  thePrs->setColor(0, 0, 0);
+  thePrs->setLineStyle(3);
+}
\ No newline at end of file
diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h
new file mode 100644 (file)
index 0000000..099d547
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ConstructionPlugin_Axis.h
+// Created:     12 Dec 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ConstructionPlugin_Axis_H
+#define ConstructionPlugin_Axis_H
+
+#include "ConstructionPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_ICustomPrs.h>
+
+
+/// Point kind
+const std::string CONSTRUCTION_AXIS_KIND("Axis");
+
+/// attribute name for first point
+const std::string POINT_ATTR_FIRST = "firstPoint";
+
+/// attribute name for second point
+const std::string POINT_ATTR_SECOND = "secondPoint";
+
+/**\class ConstructionPlugin_Axis
+ * \ingroup DataModel
+ * \brief Feature for creation of the new axis in PartSet.
+ */
+class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+{
+ public:
+  /// Returns the kind of a feature
+  CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = CONSTRUCTION_AXIS_KIND;
+    return MY_KIND;
+  }
+
+  /// Creates a new part document if needed
+  CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Construction result is allways recomuted on the fly
+  CONSTRUCTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
+  /// Use plugin manager for features creation
+  ConstructionPlugin_Axis();
+
+  /// Customize presentation of the feature
+  virtual void customisePresentation(AISObjectPtr thePrs);
+};
+
+
+#endif
\ No newline at end of file
index 008d139525b066dd750a13e0b05868bcec707bd0..bd7465df58ac73ecb6e241eb462f02babbd69cdb 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "ConstructionPlugin_Plugin.h"
 #include "ConstructionPlugin_Point.h"
+#include "ConstructionPlugin_Axis.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
@@ -22,6 +23,9 @@ FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID)
   if (theFeatureID == CONSTRUCTION_POINT_KIND) {
     return FeaturePtr(new ConstructionPlugin_Point);
   }
+  else if (theFeatureID == CONSTRUCTION_AXIS_KIND) {
+    return FeaturePtr(new ConstructionPlugin_Axis);
+  }
   // feature of such kind is not found
   return FeaturePtr();
 }
index 56e921ab5a64ef527f49a44f3c76ad1198bf580e..637b96193d5d0f205d926920c550171cccb00cc0 100644 (file)
@@ -34,13 +34,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature
     return MY_KIND;
   }
 
-  /// Returns to which group in the document must be added feature
-  CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup()
-  {
-    static std::string MY_GROUP = "Construction";
-    return MY_GROUP;
-  }
-
   /// Creates a new part document if needed
   CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
 
diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml
new file mode 100644 (file)
index 0000000..e6472b6
--- /dev/null
@@ -0,0 +1,17 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+  <shape_selector id="firstPoint" 
+    label="First point" 
+    icon=":icons/point.png" 
+    tooltip="Select a first point for the axis"
+    shape_types="vertex"
+  />
+  <shape_selector id="secondPoint"
+    label="Second point"
+    icon=":icons/point.png"
+    tooltip="Select a second point for the axis"
+    shape_types="vertex">
+    <validator id="PartSet_DifferentObjects"/>
+  </shape_selector>
+</source>
index d7d623536ce7814dd3ec3550dace43e3296a661c..2d670f9633b6e470b7d8b99f663b753590362228 100644 (file)
@@ -14,9 +14,9 @@
         id="Axis"
         title="Axis"
         tooltip="Create a new axis"
-        icon=":icons/axis.png"
-        keysequence=""
-        internal="true" />
+        icon=":icons/axis.png">
+        <source path="axis_widget.xml" />
+      </feature>
       <feature
         id="Plane"
         title="Plane"
index 1e6566c093c093a03006127fe66049d5af3f6364..24e07eb08d732dc33fc6394067aacc08d967c31a 100644 (file)
@@ -325,3 +325,20 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale)
     }
   }
 }
+
+
+void GeomAPI_AISObject::setLineStyle(int theStyle)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
+    if (aDrawer->HasLineAspect())
+      aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+    if (aDrawer->HasWireAspect())
+      aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+    //else {
+    //  Quantity_NameOfColor aCol = Quantity_NOC_RED;
+    //  aDrawer->SetLineAspect(new Prs3d_LineAspect(aCol, (Aspect_TypeOfLine)theStyle, 1));
+    //}
+  }
+}
index 1477c5a139634265678b7b0ff10b4ee31f1da515..ce2d7e0d494232ef910948fb28d0ffed96db4eb0 100644 (file)
@@ -103,6 +103,10 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
   /// Sets marker type for vertex.
   /// The type has to be defined according to Acpect_TypeOfMarker
   void setPointMarker(int theType, double theScale);
+
+  /// Set line type of edges
+  /// Has to be defined according to Aspect_TypeOfLine
+  void setLineStyle(int theStyle);
 };
 
 //! Pointer on attribute object
index 2ff0726bfd30020ed6664b6e95b12e9d1a14b2da..f57605c8c4fe2ee37f078ab46f0ea545f8d7d5e5 100644 (file)
@@ -8,7 +8,10 @@
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Shape.h>
 #include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRep_Tool.hxx>
 #include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <gp_Pnt.hxx>
 
 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
     std::shared_ptr<GeomAPI_Pnt> thePoint)
@@ -20,3 +23,16 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
   aRes->setImpl(new TopoDS_Shape(aVertex));
   return aRes;
 }
+
+
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(std::shared_ptr<GeomAPI_Shape> theVertex)
+{
+  TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
+  if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
+    TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
+    gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+    std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+    return aPnt;
+  }
+  return std::shared_ptr<GeomAPI_Pnt>();
+}
index 64e479ce1cfbb300b3e16b840b43eadbaae788ba..893c70c977fa77c999d15b11215584169ccf3f72 100644 (file)
@@ -21,8 +21,11 @@ class GeomAPI_Pnt;
 class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder
 {
  public:
-  /// Creates linear edge by two points
+  /// Creates a shape by point
   static std::shared_ptr<GeomAPI_Shape> point(std::shared_ptr<GeomAPI_Pnt> thePoint);
+
+  /// Return point by shape vertex
+  static std::shared_ptr<GeomAPI_Pnt> point(std::shared_ptr<GeomAPI_Shape> theVertex);
 };
 
 #endif
index 388419ad7f7068cd4d4825071dc9d94c96a14410..b13d3542e464f744187d146f00de632e315adec1 100644 (file)
@@ -542,7 +542,7 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t
 void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
-  if (aOperation->isEditOperation()) {
+  if (aOperation && aOperation->isEditOperation()) {
     std::string aId = aOperation->id().toStdString();
     if ((aId == SketchPlugin_ConstraintLength::ID()) ||
       (aId == SketchPlugin_ConstraintDistance::ID()) ||
index 3a530c2f4aff8b6249612d07499c3fe9ec22a149..3e6314a962b2b6957340bbf3028ca11319dc9d1e 100644 (file)
@@ -59,13 +59,13 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
 
     GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
     bool isShading = false;
-    if (aPrs) {
+    if (aPrs.get() != NULL) {
       anAIS = aPrs->getAISObject(AISObjectPtr());
     } else {
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-      if (aResult) {
+      if (aResult.get() != NULL) {
         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-        if (aShapePtr) {
+        if (aShapePtr.get() != NULL) {
           anAIS = AISObjectPtr(new GeomAPI_AISObject());
           anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
           //anAIS->createShape(aShapePtr);