]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1114: Provide selection of origin and axis of trihedron with reference to...
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 26 Apr 2016 08:47:08 +0000 (11:47 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 26 Apr 2016 08:47:24 +0000 (11:47 +0300)
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/GeomAPI/GeomAPI_Vertex.cpp
src/GeomAPI/GeomAPI_Vertex.h
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/InitializationPlugin/InitializationPlugin_Plugin.h
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h
src/XGUI/XGUI_Selection.cpp

index 8a6c2a5d0c23fb8ea0dad5ad7b35404771e1c90c..20a11909a88d57c8b2fdf4e3250c57322b544b9f 100644 (file)
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Vertex.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_PointBuilder.h>
 
@@ -36,6 +38,12 @@ void ConstructionPlugin_Axis::initAttributes()
                        ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
                        ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::Y_DIRECTION(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(),
+                       ModelAPI_AttributeDouble::typeId());
 }
 
 void ConstructionPlugin_Axis::createAxisByTwoPoints()
@@ -64,6 +72,38 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints()
   }
 }
 
+
+void ConstructionPlugin_Axis::createAxisByPointAndDirection()
+{
+  AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
+  AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION());
+  AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION());
+  AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION());
+  if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) && 
+      (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) {
+    GeomShapePtr aShape1 = aRef1->value();
+    if (!aShape1.get())
+      aShape1 = aRef1->context()->shape();
+
+    std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aXAttr->value(), 
+                                                               aYAttr->value(),
+                                                               aZAttr->value()));
+    if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) {
+      std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+      std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aVertex);
+      if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
+        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+        ResultConstructionPtr aConstr = document()->createConstruction(data());
+        aConstr->setInfinite(true);
+        aConstr->setShape(anEdge);
+        setResult(aConstr);
+      }
+    }
+  }
+}
+
+
 void ConstructionPlugin_Axis::createAxisByCylindricalFace()
 {
     std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
@@ -78,6 +118,8 @@ void ConstructionPlugin_Axis::createAxisByCylindricalFace()
     }
 }
 
+
+
 void ConstructionPlugin_Axis::execute()
 {
   AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
@@ -86,6 +128,8 @@ void ConstructionPlugin_Axis::execute()
     createAxisByTwoPoints();
   } else if (aMethodType == "AxisByCylindricalFaceCase") {
     createAxisByCylindricalFace();
+  } else if (aMethodType == "AxisByPointAndDirection") {
+    createAxisByPointAndDirection();
   }
 }
 
index ffaa95d04ed0614e0a1de31334fdd197250b9544..4c51a1d40f9fedbdab675eb61a8721becda16dd6 100644 (file)
@@ -58,6 +58,27 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     return CYLINDRICAL_FACE_ATTR;
   }
 
+  /// attribute name for X direction
+  inline static const std::string& X_DIRECTION()
+  {
+    static const std::string ATTR_X_DIRECTION("X_Direction");
+    return ATTR_X_DIRECTION;
+  }
+
+  /// attribute name for Y direction
+  inline static const std::string& Y_DIRECTION()
+  {
+    static const std::string ATTR_Y_DIRECTION("Y_Direction");
+    return ATTR_Y_DIRECTION;
+  }
+
+  /// attribute name for Y direction
+  inline static const std::string& Z_DIRECTION()
+  {
+    static const std::string ATTR_Z_DIRECTION("Z_Direction");
+    return ATTR_Z_DIRECTION;
+  }
+
   /// Returns a minimal length for axis
   inline static const double MINIMAL_LENGTH() { return 1.e-5; }
 
@@ -82,6 +103,8 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
   void createAxisByTwoPoints();
   /// Creates a new axis as copy of cylindrical face axis
   void createAxisByCylindricalFace();
+  /// Creates a new axis by point and direction
+  void createAxisByPointAndDirection();
 };
 
 
index b917837a09cfcaa4e9589598625f7a4d4f63765e..27060572ce1ab6de8ac8b49ba15bfc027be5b683 100644 (file)
@@ -12,6 +12,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
 #include <gp_Pnt.hxx>
 #include <Precision.hxx>
 
@@ -27,6 +28,14 @@ GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
   }
 }
 
+GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ)
+{
+  TopoDS_Vertex aVertex;
+  BRep_Builder aBuilder;
+  aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion());
+  setImpl(new TopoDS_Shape(aVertex));
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
index 9baf0dcdc08bf4a8572ff5b2168478b9d005161e..c1ec7109c3d669158ffad59dd374360ddc6f1d32 100644 (file)
@@ -23,10 +23,14 @@ public:
   GEOMAPI_EXPORT 
    GeomAPI_Vertex();
 
-   /// Creation of edge by the edge-shape
+   /// Creation of vertex by the vertex-shape
   GEOMAPI_EXPORT 
    GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
+   /// Creation of vertex by 3d coordinates
+  GEOMAPI_EXPORT 
+   GeomAPI_Vertex(double theX, double theY, double theZ);
+
   /// Returns the first vertex coordinates of the edge 
   GEOMAPI_EXPORT 
   std::shared_ptr<GeomAPI_Pnt> point();
index 7418469e6202eeb8ff2643879214bd367a3ec658..b896d594ba9ddb904b52d57dc81f17b682e71389 100644 (file)
@@ -6,6 +6,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Result.h>
 
@@ -46,7 +47,11 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
         new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
     Events_Loop::loop()->send(aMsg);
 
-    aFeatures.push_back(createPoint(aDoc));
+    FeaturePtr aOrigin = createPoint(aDoc, "Origin", 0., 0., 0.);
+    aFeatures.push_back(aOrigin);
+    aFeatures.push_back(createAxis(aDoc, aOrigin, 100., 0., 0.));
+    aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 100., 0.));
+    aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 0., 100.));
     aFeatures.push_back(createPlane(aDoc, 1., 0., 0.));
     aFeatures.push_back(createPlane(aDoc, 0., -1., 0.));
     aFeatures.push_back(createPlane(aDoc, 0., 0., 1.));
@@ -110,13 +115,14 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t
   return aPlane;
 }
 
-FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
+FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const std::string& theName,
+                                                    double theX, double theY, double theZ)
 {
   std::shared_ptr<ModelAPI_Feature> aPoint = theDoc->addFeature("Point");
-  aPoint->real("x")->setValue(0.);
-  aPoint->real("y")->setValue(0.);
-  aPoint->real("z")->setValue(0.);
-  aPoint->data()->setName("Origin");
+  aPoint->real("x")->setValue(theX);
+  aPoint->real("y")->setValue(theY);
+  aPoint->real("z")->setValue(theZ);
+  aPoint->data()->setName(theName);
   aPoint->setInHistory(aPoint, false);  // don't show automatically created feature in the features history
 
   // the point should be executed in order to build the feature result immediatelly
@@ -127,3 +133,31 @@ FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
 
   return aPoint;
 }
+
+FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePtr theOrigin,
+                                                   double theX, double theY, double theZ)
+{
+  std::shared_ptr<ModelAPI_Feature> aAxis = theDoc->addFeature("Axis");
+  aAxis->string("CreationMethod")->setValue("AxisByPointAndDirection");
+
+  ResultPtr aResult = theOrigin->firstResult();
+  aAxis->selection("FirstPoint")->setValue(aResult, aResult->shape());
+
+  aAxis->real("X_Direction")->setValue(theX);
+  aAxis->real("Y_Direction")->setValue(theY);
+  aAxis->real("Z_Direction")->setValue(theZ);
+
+  if (theX != 0) {
+    aAxis->data()->setName("OX");
+  } else if (theY != 0) {
+    aAxis->data()->setName("OY");
+  } else if (theZ != 0) {
+    aAxis->data()->setName("OZ");
+  }
+  aAxis->setInHistory(aAxis, false);  // don't show automatically created feature in the features history
+  aAxis->execute();
+  aAxis->data()->execState(ModelAPI_StateDone);
+  aAxis->firstResult()->data()->execState(ModelAPI_StateDone);
+
+  return aAxis;
+}
index 42d157703e7d9c46cd52a373e83229c11bbd4ac6..c44c7a43fa8a51f0805f211a17bd8511ca09fc77 100644 (file)
@@ -35,7 +35,21 @@ class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public Events_Li
   FeaturePtr createPlane(DocumentPtr theDoc, double theX, double theY, double theZ);
   /// Creates the origin point in (0,0,0)
   /// \param theDoc - document to contain a "point" feature
-  FeaturePtr createPoint(DocumentPtr theDoc);
+  /// \param theName - name of the point
+  /// \param theX - X coordinate
+  /// \param theY - Y coordinate
+  /// \param theZ - Z coordinate
+  FeaturePtr createPoint(DocumentPtr theDoc, const std::string& theName, 
+                         double theX, double theY, double theZ);
+
+  /// Creates an axis which is started from origin point
+  /// \param theDoc - document to contain an "axis" feature
+  /// \param theOrigin - origin point feature
+  /// \param theX - X of direction point
+  /// \param theY - Y of direction point
+  /// \param theZ - Z of direction point
+  FeaturePtr createAxis(DocumentPtr theDoc, FeaturePtr theOrigin, 
+                        double theX, double theY, double theZ);
 };
 
 #endif
index 6761331282f4a3975a22792370c05bf94f0d75ac..a0d88f734ee51265ee2c33fa6c151e463e8f2133 100644 (file)
@@ -215,6 +215,17 @@ bool ParametersPlugin_WidgetParamsMgr::restoreValueCustom()
 
 void ParametersPlugin_WidgetParamsMgr::activateCustom()
 {
+  updateParametersFeatures();
+  updateParametersPart();
+  updateFeaturesPart();
+
+  myFeatures->setExpanded(true);
+  myParameters->setExpanded(true);
+}
+
+void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
+{
+  myParametersList.clear();
   FeaturePtr aFeature = feature();
   DocumentPtr aDoc = aFeature->document();
   int aNbParam = aDoc->size(ModelAPI_ResultParameter::group());
@@ -227,11 +238,6 @@ void ParametersPlugin_WidgetParamsMgr::activateCustom()
       myParametersList.append(aParamFeature);
     }
   }
-  updateParametersPart();
-  updateFeaturesPart();
-
-  myFeatures->setExpanded(true);
-  myParameters->setExpanded(true);
 }
 
 void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
@@ -530,7 +536,9 @@ void ParametersPlugin_WidgetParamsMgr::onRemove()
 
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+    updateParametersFeatures();
     updateFeaturesPart();
+    updateParametersPart();
   }
 }
 
@@ -567,6 +575,13 @@ void ParametersPlugin_WidgetParamsMgr::onUp()
   myParameters->insertChild(aCurrentPos - 1, aCurrentItem);
 
   selectItemScroll(aCurrentItem);
+
+  //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+  //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
+  //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  //updateParametersFeatures();
+  //updateParametersPart();
+  //updateFeaturesPart();
 }
 
 void ParametersPlugin_WidgetParamsMgr::onDown()
@@ -591,6 +606,13 @@ void ParametersPlugin_WidgetParamsMgr::onDown()
   myParameters->insertChild(aCurrentPos + 1, aCurrentItem);
 
   selectItemScroll(aCurrentItem);
+
+  //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+  //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
+  //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  //updateParametersFeatures();
+  //updateParametersPart();
+  //updateFeaturesPart();
 }
 
 
index eb3903e03c3861cbebb82b37c45b749f6c3a2462..91c772da0c073bba2dd39b9b039e0ff180e88c7c 100644 (file)
@@ -103,6 +103,8 @@ private:
   QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures) const;
   QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;
 
+  void updateParametersFeatures();
+
   QTreeWidget* myTable;
   QTreeWidgetItem* myFeatures;
   QTreeWidgetItem* myParameters;
index 6091e71f40f739945710091312cc5aab0a7aaa2a..eb59cf8c8274cdcc3cd2044754da17d06412c4a8 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Axis.hxx>
@@ -146,32 +148,49 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
 #ifdef DEBUG_DELIVERY
     // Fill by trihedron shapes
     Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(anIO);
+    DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
+    int aSize = aDoc->size(ModelAPI_ResultConstruction::group());
+    ObjectPtr aObj;
     if (!aAxis.IsNull()) {
       // an Axis from Trihedron
-      Handle(Geom_Line) aLine = aAxis->Component();
-      Handle(Prs3d_DatumAspect) DA = aAxis->Attributes()->DatumAspect();
-      Handle(Geom_TrimmedCurve) aTLine = new Geom_TrimmedCurve(aLine, 0, DA->FirstAxisLength());
-
-      BRep_Builder aBuilder;      
-      TopoDS_Edge aEdge;
-      aBuilder.MakeEdge(aEdge, aTLine, Precision::Confusion());
-      if (!aEdge.IsNull()) {
-        std::shared_ptr<GeomAPI_Shape> aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-        aGeomShape->setImpl(new TopoDS_Shape(aEdge));
-        thePrs->setShape(aGeomShape);
+      gp_Lin aLine = aAxis->Component()->Lin();
+      gp_Dir aDir = aLine.Direction();
+      std::string aAxName;
+      if (aDir.X() == 1.) 
+        aAxName = "OX";
+      else if (aDir.Y() == 1.)
+        aAxName = "OY";
+      else if (aDir.Z() == 1.)
+        aAxName = "OZ";
+      if (aAxName.length() > 0) {
+        ResultPtr aAx;
+        for (int i = 0; i < aSize; i++) {
+          aObj = aDoc->object(ModelAPI_ResultConstruction::group(), i);
+          if (aObj->data()->name() == aAxName) {
+            aAx = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+            break;
+          }
+        }
+        if (aAx.get()) {
+          thePrs->setObject(aAx);
+          thePrs->setShape(aAx->shape());
+        }
       }
     } else {
       Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(anIO);
       if (!aPoint.IsNull()) {
-        // A point from trihedron
-        Handle(Geom_Point) aPnt = aPoint->Component();
-        BRep_Builder aBuilder;
-        TopoDS_Vertex aVertex;
-        aBuilder.MakeVertex(aVertex, aPnt->Pnt(), Precision::Confusion());
-        if (!aVertex.IsNull()) {
-          std::shared_ptr<GeomAPI_Shape> aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-          aGeomShape->setImpl(new TopoDS_Shape(aVertex));
-          thePrs->setShape(aGeomShape);
+        // An origin point from trihedron
+        ResultPtr aOrigin;
+        for (int i = 0; i < aSize; i++) {
+          aObj = aDoc->object(ModelAPI_ResultConstruction::group(), i);
+          if (aObj->data()->name() == "Origin") {
+            aOrigin = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+            break;
+          }
+        }
+        if (aOrigin.get()) {
+          thePrs->setObject(aOrigin);
+          thePrs->setShape(aOrigin->shape());
         }
       }
     }