Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Dec 2014 16:30:17 +0000 (19:30 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 12 Dec 2014 16:30:17 +0000 (19:30 +0300)
12 files changed:
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp [new file with mode: 0644]
src/ConstructionPlugin/ConstructionPlugin_Plane.h [new file with mode: 0644]
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/plane_widget.xml [new file with mode: 0644]
src/ConstructionPlugin/plugin-Construction.xml
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAPI/GeomAPI_Pnt.cpp
src/GeomAPI/GeomAPI_Pnt.h
src/XGUI/XGUI_Displayer.cpp

index 0ddbb7f1b42a4807c3b210520adb9dd1fbe6e4df..0a1847283a9633002b259e4444b6920be189c3c9 100644 (file)
@@ -8,18 +8,21 @@ SET(PROJECT_HEADERS
     ConstructionPlugin_Plugin.h
     ConstructionPlugin_Point.h
        ConstructionPlugin_Axis.h
+       ConstructionPlugin_Plane.h
 )
 
 SET(PROJECT_SOURCES
     ConstructionPlugin_Plugin.cpp
     ConstructionPlugin_Point.cpp
        ConstructionPlugin_Axis.cpp
+       ConstructionPlugin_Plane.cpp
 )
 
 SET(XML_RESOURCES
   plugin-Construction.xml
   point_widget.xml
   axis_widget.xml
+  plane_widget.xml
 )
 
 SET(PROJECT_LIBRARIES
index de672a25b5fc5881122559b4e98421c19dbf7d30..69b31a9f0feed35170699c0e04d0606a090ebd16 100644 (file)
@@ -15,7 +15,7 @@
 
 using namespace std;
 
-static const double MINIMAL_LENGTH      = 1.e-5;
+static const double MINIMAL_LENGTH = 1.e-5;
 
 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
 {
diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
new file mode 100644 (file)
index 0000000..37faed9
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ConstructionPlugin_Plane.cpp
+// Created:     12 Dec 2014
+// Author:      Vitaly Smetannikov
+
+#include "ConstructionPlugin_Plane.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+
+
+#define PLANE_SIZE 300
+
+ConstructionPlugin_Plane::ConstructionPlugin_Plane()
+{
+}
+
+void ConstructionPlugin_Plane::initAttributes()
+{
+  data()->addAttribute(FACE_ATTR,  ModelAPI_AttributeSelection::type());
+  data()->addAttribute(DISTANCE_ATTR, ModelAPI_AttributeDouble::type());
+}
+
+void ConstructionPlugin_Plane::execute()
+{
+  AttributeSelectionPtr aFaceAttr = data()->selection(FACE_ATTR);
+  AttributeDoublePtr aDistAttr = data()->real(DISTANCE_ATTR);
+  if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) && 
+    aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
+
+    double aDist = aDistAttr->value();
+    GeomShapePtr aShape = aFaceAttr->value();
+    if (aShape.get() != NULL) {
+      std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
+      std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
+      std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
+
+      aOrig->translate(aDir, aDist);
+      std::shared_ptr<GeomAPI_Shape> aPlane = 
+        GeomAlgoAPI_FaceBuilder::square(aOrig, aDir, PLANE_SIZE);
+      ResultConstructionPtr aConstr = document()->createConstruction(data());
+      aConstr->setShape(aPlane);
+      setResult(aConstr);
+    }
+  }
+}
+
+void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
+{
+  thePrs->setColor(50, 255, 50);
+  thePrs->setTransparensy(0.6);
+}
\ No newline at end of file
diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h
new file mode 100644 (file)
index 0000000..e58dd2e
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ConstructionPlugin_Plane.h
+// Created:     12 Dec 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ConstructionPlugin_Plane_H
+#define ConstructionPlugin_Plane_H
+
+#include "ConstructionPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_ICustomPrs.h>
+
+/// Point kind
+const std::string CONSTRUCTION_PLANE_KIND("Plane");
+
+/// attribute name for base face
+const std::string FACE_ATTR = "planeFace";
+
+/// attribute name for distance
+const std::string DISTANCE_ATTR = "distance";
+
+/**\class ConstructionPlugin_Axis
+ * \ingroup DataModel
+ * \brief Feature for creation of the new axis in PartSet.
+ */
+class ConstructionPlugin_Plane : 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_PLANE_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_Plane();
+
+  /// Customize presentation of the feature
+  virtual void customisePresentation(AISObjectPtr thePrs);
+};
+
+#endif
\ No newline at end of file
index bd7465df58ac73ecb6e241eb462f02babbd69cdb..4ce70ae037c789ce3e0e7aa0cf788c3589355543 100644 (file)
@@ -3,6 +3,7 @@
 #include "ConstructionPlugin_Plugin.h"
 #include "ConstructionPlugin_Point.h"
 #include "ConstructionPlugin_Axis.h"
+#include "ConstructionPlugin_Plane.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
@@ -26,6 +27,9 @@ FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID)
   else if (theFeatureID == CONSTRUCTION_AXIS_KIND) {
     return FeaturePtr(new ConstructionPlugin_Axis);
   }
+  else if (theFeatureID == CONSTRUCTION_PLANE_KIND) {
+    return FeaturePtr(new ConstructionPlugin_Plane);
+  }
   // feature of such kind is not found
   return FeaturePtr();
 }
diff --git a/src/ConstructionPlugin/plane_widget.xml b/src/ConstructionPlugin/plane_widget.xml
new file mode 100644 (file)
index 0000000..bf062da
--- /dev/null
@@ -0,0 +1,13 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+  <shape_selector id="planeFace" 
+                  label="Plane face" 
+                  tooltip="Select a planar face for plane definition"
+                  shape_types="face"
+                  use_subshapes="true" />
+  <doublevalue id="distance" 
+               label="Distance" 
+               tooltip="Distance from selected face to plane" 
+               default="0" />
+</source>
index 2d670f9633b6e470b7d8b99f663b753590362228..68a3e4e7c9f484690594266c2dfae4a519db8899 100644 (file)
@@ -21,9 +21,9 @@
         id="Plane"
         title="Plane"
         tooltip="Create a new plane"
-        icon=":icons/plane.png"
-        keysequence=""
-        internal="true" />
+        icon=":icons/plane.png">
+        <source path="plane_widget.xml" />
+      </feature>
     </group>
   </workbench>
-</plugin>
\ No newline at end of file
+</plugin>
index 24e07eb08d732dc33fc6394067aacc08d967c31a..a2b39e45217fcb1ae3427531db1eb20ffab599a0 100644 (file)
@@ -20,6 +20,7 @@
 #include <BRepBndLib.hxx>
 
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_InteractiveContext.hxx>
 #include <AIS_LengthDimension.hxx>
 #include <AIS_ParallelRelation.hxx>
 #include <AIS_PerpendicularRelation.hxx>
@@ -336,9 +337,16 @@ void GeomAPI_AISObject::setLineStyle(int theStyle)
       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));
-    //}
+  }
+}
+
+
+void GeomAPI_AISObject::setTransparensy(double theVal)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
+    if (!aContext.IsNull())
+      aContext->SetTransparency(anAIS, theVal, false);
   }
 }
index ce2d7e0d494232ef910948fb28d0ffed96db4eb0..a76016bd6d738989f04238cb02037f5b291f17bb 100644 (file)
@@ -107,6 +107,9 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
   /// Set line type of edges
   /// Has to be defined according to Aspect_TypeOfLine
   void setLineStyle(int theStyle);
+
+  /// Set transparency of the presentation (theVal = 0 ... 1)
+  void setTransparensy(double theVal);
 };
 
 //! Pointer on attribute object
index b4ad659760d8bf2c38970f6ff2b4ec6e9cedb320..d9bc12b6f5704927313f93c22b19f43e20822e22 100644 (file)
@@ -73,3 +73,12 @@ std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_P
   double aY = aVec.X() * theDirY->x() + aVec.Y() * theDirY->y() + aVec.Z() * theDirY->z();
   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
 }
+
+
+void GeomAPI_Pnt::translate(const std::shared_ptr<GeomAPI_Dir>& theDir, double theDist)
+{
+  gp_Vec aVec(theDir->impl<gp_Dir>());
+  aVec.Normalize();
+  aVec.Multiply(theDist);
+  MY_PNT->Translate(aVec);
+}
index c04dec42bb5726433682245dd6d337df902e21e0..835e24939a601e84990387ff7e405960d0bd53eb 100644 (file)
@@ -51,6 +51,9 @@ class GEOMAPI_EXPORT GeomAPI_Pnt : public GeomAPI_Interface
   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
                                         const std::shared_ptr<GeomAPI_Dir>& theDirX,
                                         const std::shared_ptr<GeomAPI_Dir>& theDirY);
+
+  /// Translates the point along direction theDir on distance theDist
+  void translate(const std::shared_ptr<GeomAPI_Dir>& theDir, double theDist);
 };
 
 #endif
index 3e6314a962b2b6957340bbf3028ca11319dc9d1e..17f52eb5f9d01d15f23be14a58cd1c1862a1cb74 100644 (file)
@@ -88,14 +88,15 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!anAISIO.IsNull()) {
     myResult2AISObjectMap[theObject] = theAIS;
+    aContext->Display(anAISIO, false);
+    aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
+
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     if (aFeature.get() != NULL) {
       GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
       if (aCustPrs.get() != NULL)
         aCustPrs->customisePresentation(theAIS);
     }
-    aContext->Display(anAISIO, false);
-    aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, isUpdateViewer);
     if (aContext->HasOpenedContext()) {
       if (myUseExternalObjects) {
         if (myActiveSelectionModes.size() == 0)
@@ -108,6 +109,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
       }
     }
   }
+  if (isUpdateViewer)
+    updateViewer();
 }
 
 void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)