]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Default planes and origin initialization
authorsbh <sergey.belash@opencascade.com>
Thu, 12 Mar 2015 16:04:35 +0000 (19:04 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 12 Mar 2015 16:04:35 +0000 (19:04 +0300)
17 files changed:
src/Config/plugins.xml
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.h
src/ConstructionPlugin/axis_widget.xml
src/ConstructionPlugin/plane_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h
src/InitializationPlugin/CMakeLists.txt
src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp [deleted file]
src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h [deleted file]
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/InitializationPlugin/InitializationPlugin_Plugin.h
src/InitializationPlugin/plugin-Initialization.xml [deleted file]
src/Model/Model_Application.cpp
src/Model/Model_Update.cpp

index 3923ac8e9a0ad2341157e6a5c134ee57122ec377..7ac11fe50f01d1a432fc2f0f2113d0b556614341 100644 (file)
@@ -7,7 +7,7 @@
   <plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
   <plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
   <plugin script="ConnectorPlugin" configuration="plugin-Connector.xml" dependency="Geometry"/>
-  <plugin library="InitializationPlugin" configuration="plugin-Initialization.xml"/>
+  <plugin library="InitializationPlugin"/>
   <plugin library="SketchSolver"/>
   <plugin library="GeomValidators"/>
   <plugin library="DFBrowser" internal="true"/>
index 8e90fae27eb89033d6f4e06ed2c314117a08c096..5017f496a97af4842da4c557aa6a65478f362dfa 100644 (file)
@@ -61,9 +61,7 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints()
 
 void ConstructionPlugin_Axis::execute()
 {
-  AttributePtr anAttr = data()->attribute(ConstructionPlugin_Axis::METHOD());
-  AttributeStringPtr aMethodTypeAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
+  AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
   std::string aMethodType = aMethodTypeAttr->value();
   if (aMethodType == "AxisByPointsCase") {
     createAxisByTwoPoints();
index cbf40fce70b04a0b1861e7b42b373dda01bb0613..df8aedcfde5bf9fd4d32414aaf67557dc7f554f2 100644 (file)
@@ -36,25 +36,25 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
   /// attribute name for first point
   inline static const std::string& METHOD()
   {
-    static const std::string METHOD_ATTR("creationMethod");
+    static const std::string METHOD_ATTR("CreationMethod");
     return METHOD_ATTR;
   }
   /// attribute name for first point
   inline static const std::string& POINT_FIRST()
   {
-    static const std::string POINT_ATTR_FIRST("firstPoint");
+    static const std::string POINT_ATTR_FIRST("FirstPoint");
     return POINT_ATTR_FIRST;
   }
   /// attribute name for second point
   inline static const std::string& POINT_SECOND()
   {
-    static const std::string POINT_ATTR_SECOND("secondPoint");
+    static const std::string POINT_ATTR_SECOND("SecondPoint");
     return POINT_ATTR_SECOND;
   }
   /// attribute name for second point
   inline static const std::string& CYLINDRICAL_FACE()
   {
-    static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace");
+    static const std::string CYLINDRICAL_FACE_ATTR("CylindricalFace");
     return CYLINDRICAL_FACE_ATTR;
   }
 
index 501d9664e7762c01e75548bf4a8c275445a181b7..5fecd65240f47ab593168de9c74efb98a8eabe95 100644 (file)
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeString.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <GeomAPI_Pnt2d.h>
 
-
-#define PLANE_SIZE 300
-
 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
 {
 }
 
 void ConstructionPlugin_Plane::initAttributes()
 {
+  data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::type());
+  // Face & Distance
   data()->addAttribute(ConstructionPlugin_Plane::FACE(),  ModelAPI_AttributeSelection::type());
   data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::type());
+  // General equation
+  data()->addAttribute(ConstructionPlugin_Plane::A(),  ModelAPI_AttributeDouble::type());
+  data()->addAttribute(ConstructionPlugin_Plane::B(),  ModelAPI_AttributeDouble::type());
+  data()->addAttribute(ConstructionPlugin_Plane::C(),  ModelAPI_AttributeDouble::type());
+  data()->addAttribute(ConstructionPlugin_Plane::D(),  ModelAPI_AttributeDouble::type());
 }
 
 void ConstructionPlugin_Plane::execute()
+{
+  AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Plane::METHOD());
+  std::string aMethodType = aMethodTypeAttr->value();
+  std::shared_ptr<GeomAPI_Shape> aPlaneFace;
+  if (aMethodType == "PlaneByFaceAndDistance") {
+    aPlaneFace = createPlaneByFaceAndDistance();
+  } else if (aMethodType == "PlaneByGeneralEquation") {
+    aPlaneFace = createPlaneByGeneralEquation();
+  }
+  if (!aPlaneFace.get())
+    return;
+  ResultConstructionPtr aConstr = document()->createConstruction(data());
+  aConstr->setShape(aPlaneFace);
+  setResult(aConstr);
+}
+
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+{
+  std::vector<int> aColor;
+  // get color from the attribute of the result
+  if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      aColor.push_back(aColorAttr->value(0));
+      aColor.push_back(aColorAttr->value(1));
+      aColor.push_back(aColorAttr->value(2));
+    }
+  }
+  if (aColor.empty())
+    aColor = Config_PropManager::color("Visualization", "construction_plane_color",
+                                       ConstructionPlugin_Plane::DEFAULT_COLOR());
+
+  bool isCustomized = false;
+  if (aColor.size() == 3)
+    isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+  isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
+
+  return isCustomized;
+}
+
+std::shared_ptr<GeomAPI_Shape>  ConstructionPlugin_Plane::createPlaneByFaceAndDistance()
 {
   AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::FACE());
   AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE());
-  if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) && 
-    aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
+  std::shared_ptr<GeomAPI_Shape> aPlane;
+  if ((aFaceAttr.get() != NULL) &&
+      (aDistAttr.get() != NULL) &&
+      aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
 
     double aDist = aDistAttr->value();
     GeomShapePtr aShape = aFaceAttr->value();
@@ -44,17 +94,17 @@ void ConstructionPlugin_Plane::execute()
       std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
 
       aOrig->translate(aDir, aDist);
-      std::shared_ptr<GeomAPI_Pln> aNewPln = 
-        std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aOrig, aDir));
+      std::shared_ptr<GeomAPI_Pln> aNewPln = std::shared_ptr<GeomAPI_Pln>(
+          new GeomAPI_Pln(aOrig, aDir));
 
       // Create rectangular face close to the selected
       double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
       aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
 
-      std::shared_ptr<GeomAPI_Pnt> aPnt1 = 
-        std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmin, aYmin, Zmin));
-      std::shared_ptr<GeomAPI_Pnt> aPnt2 = 
-        std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmax, aYmax, Zmax));
+      std::shared_ptr<GeomAPI_Pnt> aPnt1 = std::shared_ptr<GeomAPI_Pnt>(
+          new GeomAPI_Pnt(aXmin, aYmin, Zmin));
+      std::shared_ptr<GeomAPI_Pnt> aPnt2 = std::shared_ptr<GeomAPI_Pnt>(
+          new GeomAPI_Pnt(aXmax, aYmax, Zmax));
 
       std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = aPnt1->to2D(aNewPln);
       std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = aPnt2->to2D(aNewPln);
@@ -64,38 +114,35 @@ void ConstructionPlugin_Plane::execute()
       double aWgap = aWidth * 0.1;
       double aHgap = aHeight * 0.1;
 
-      std::shared_ptr<GeomAPI_Shape> aPlane = 
-        GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, aPnt2d1->x() - aWgap, aPnt2d1->y() - aHgap, 
-                                            aWidth + 2 * aWgap, aHeight + 2 * aHgap);
-      ResultConstructionPtr aConstr = document()->createConstruction(data());
-      aConstr->setShape(aPlane);
-      setResult(aConstr);
+      aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln,
+                                                   aPnt2d1->x() - aWgap,
+                                                   aPnt2d1->y() - aHgap,
+                                                   aWidth + 2 * aWgap,
+                                                   aHeight + 2 * aHgap);
     }
   }
+  return aPlane;
 }
 
-bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createPlaneByGeneralEquation()
 {
-  std::vector<int> aColor;
-  // get color from the attribute of the result
-  if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
-    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
-    if (aColorAttr.get() && aColorAttr->size()) {
-      aColor.push_back(aColorAttr->value(0));
-      aColor.push_back(aColorAttr->value(1));
-      aColor.push_back(aColorAttr->value(2));
-    }
+  AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
+  AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
+  AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
+  AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
+  std::shared_ptr<GeomAPI_Shape> aPlaneFace;
+  if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
+      (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
+      anAttrA->isInitialized() && anAttrB->isInitialized() &&
+      anAttrC->isInitialized() && anAttrD->isInitialized() ) {
+    double aA = anAttrA->value(), aB = anAttrB->value(),
+           aC = anAttrC->value(), aD = anAttrD->value();
+    std::shared_ptr<GeomAPI_Pln> aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+    std::string kDefaultPlaneSize = "200";
+    double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
+    aSize *= 4.;
+    aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize);
   }
-  if (aColor.empty())
-    aColor = Config_PropManager::color("Visualization", "construction_plane_color",
-                                       ConstructionPlugin_Plane::DEFAULT_COLOR());
-
-  bool isCustomized = false;
-  if (aColor.size() == 3)
-    isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
-
-  isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
-
-  return isCustomized;
+  return aPlaneFace;
 }
+
index 2ff71979a32780c69cfdeda3ebb3848488322955..317d6f348232239c1b4c3c5037c5f3085d23d183 100644 (file)
@@ -41,6 +41,14 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom
     static const std::string CONSTRUCTION_PLANE_KIND("Plane");
     return CONSTRUCTION_PLANE_KIND;
   }
+
+  /// attribute name for first point
+  inline static const std::string& METHOD()
+  {
+    static const std::string METHOD_ATTR("CreationMethod");
+    return METHOD_ATTR;
+  }
+
   /// attribute name for base face
   inline static const std::string& FACE()
   {
@@ -94,6 +102,10 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom
   /// Customize presentation of the feature
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+
+ protected:
+  std::shared_ptr<GeomAPI_Shape> createPlaneByFaceAndDistance();
+  std::shared_ptr<GeomAPI_Shape> createPlaneByGeneralEquation();
 };
 
 #endif
index 7173f114c221a717744fadfb16b72a478dd964e9..44f6f0e94d6bca405d8c21adb68aea071d51113f 100644 (file)
@@ -1,16 +1,16 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <toolbox id="creationMethod">
+  <toolbox id="CreationMethod">
     <box id="AxisByPointsCase" title="By two points">
-      <shape_selector id="firstPoint"
+      <shape_selector id="FirstPoint"
         label="First point"
         icon=":icons/point.png"
         tooltip="Select a first point"
         shape_types="vertex">
         <selection_filter id="NoConstructionSubShapesFilter"/>
       </shape_selector>
-      <shape_selector id="secondPoint"
+      <shape_selector id="SecondPoint"
         label="Second point"
         icon=":icons/point.png"
         tooltip="Select a second point"
@@ -20,7 +20,7 @@
       </shape_selector>
     </box>
     <box id="AxisByCylindricalFaceCase" title="As axis of cylindrical face">
-      <shape_selector id="cylindricalFace" 
+      <shape_selector id="CylindricalFace"
         label="Main object" 
         icon=":icons/circle.png" 
         tooltip="Select a cylindrical object"
index fd3f6288116359b1854786c3377a2588723f19a6..492bffad028d5e870085e4d8d86b237c9410c098 100644 (file)
@@ -1,6 +1,10 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
+  <!-- 
+  <switch id="CreationMethod">
+    <case id="PlaneByFaceAndDistance">
+   -->
   <shape_selector id="planeFace"
                   label="Plane face"
                   tooltip="Select a planar face"
                label="Distance" 
                tooltip="Distance from selected face to plane" 
                default="0" />
+<!-- 
+    </case>
+    <case id="PlaneByGeneralEquation">
+      <doublevalue id="A" 
+                   label="A:" 
+                   tooltip="The A parameter from general plane equation (Ax+By+Cz+D=0)" 
+                   default="0" />
+      <doublevalue id="B" 
+                   label="B:" 
+                   tooltip="The B parameter from general plane equation (Ax+By+Cz+D=0)" 
+                   default="0" />
+      <doublevalue id="C" 
+                   label="C:" 
+                   tooltip="The C parameter from general plane equation (Ax+By+Cz+D=0)" 
+                   default="0" />
+      <doublevalue id="D" 
+                   label="D:" 
+                   tooltip="The D parameter from general plane equation (Ax+By+Cz+D=0)" 
+                   default="0" />
+    </case>
+  </switch>
+ -->
 </source>
index 6f262f536531617248435a95f8b60710a3072650..a00f8d8c0972a2b00a6dd60c83e5a451071df0db 100644 (file)
@@ -12,6 +12,7 @@
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
 
+
 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
     std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
     const double theSize)
@@ -27,6 +28,19 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
   return aRes;
 }
 
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
+    std::shared_ptr<GeomAPI_Pln> thePlane,
+    const double theSize)
+{
+  // half of the size in each direction from the center
+  BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
+                                       -theSize / 2., theSize / 2.,
+                                       -theSize / 2., theSize / 2.);
+  std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+  aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
+  return aRes;
+}
+
 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
     std::shared_ptr<GeomAPI_Shape> theFace)
 {
@@ -53,9 +67,7 @@ std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
   return aResult;
 }
 
-
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::
-  planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
              double theX, double theY,
              double theWidth, double theHeight)
 {
index 7db03a41b72cd57084eef25a5c4182e68756ff0f..d71ec0b9cff9c7c8eb3794bbc7c0cbe38e067d16 100644 (file)
@@ -27,6 +27,10 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder
   static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pnt> theCenter,
                                                  std::shared_ptr<GeomAPI_Dir> theNormal,
                                                  const double theSize);
+  /// Creates square planar face by given point of the center,
+  /// normal to the plane and size of square
+  static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pln> thePlane,
+                                               const double theSize);
 
   /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
   static std::shared_ptr<GeomAPI_Pln> plane(std::shared_ptr<GeomAPI_Shape> theFace);
index 407d3cc47b5a1747a84c3920e0d76857de62d5fd..717e200abce89d6a9d0c14c8dcaa26d684da17cb 100644 (file)
@@ -9,17 +9,16 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
 SET(PROJECT_HEADERS
     InitializationPlugin.h
     InitializationPlugin_Plugin.h
-    InitializationPlugin_OriginPlanesFeature.h
+    #InitializationPlugin_OriginPlanesFeature.h
 )
  
 SET(PROJECT_SOURCES
     InitializationPlugin_Plugin.cpp
-    InitializationPlugin_OriginPlanesFeature.cpp
+    #InitializationPlugin_OriginPlanesFeature.cpp
 )
 
-SET(XML_RESOURCES
-    plugin-Initialization.xml
-)
+#SET(XML_RESOURCES
+#)
 
 SET(PROJECT_LIBRARIES
     Events
@@ -33,4 +32,4 @@ ADD_LIBRARY(InitializationPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${
 TARGET_LINK_LIBRARIES(InitializationPlugin ${PROJECT_LIBRARIES})
 
 INSTALL(TARGETS InitializationPlugin DESTINATION plugins)
-INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
+#INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
diff --git a/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp b/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp
deleted file mode 100644 (file)
index 8d06ee7..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-/*
- * InitializationPlugin_OriginPlanesFeature.cpp
- *
- *  Created on: Aug 28, 2014
- *      Author: sbh
- */
-
-#include <InitializationPlugin_OriginPlanesFeature.h>
-
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_AttributeDouble.h>
-
-InitializationPlugin_OriginPlanesFeature::InitializationPlugin_OriginPlanesFeature()
-: ModelAPI_Feature()
-{
-}
-
-InitializationPlugin_OriginPlanesFeature::~InitializationPlugin_OriginPlanesFeature()
-{
-}
-
-/*
- * Request for initialization of data model of the feature: adding all attributes
- */
-void InitializationPlugin_OriginPlanesFeature::initAttributes()
-{
-}
-
-/*
- * Computes or recomputes the results
- */
-void InitializationPlugin_OriginPlanesFeature::execute()
-{
-  std::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
-  std::shared_ptr<ModelAPI_Document> aDoc = aSession->activeDocument();
-  aSession->startOperation();
-  createPoint(aDoc);
-
-  //std::shared_ptr<ModelAPI_Feature> aPlane = aDoc->addFeature(ConstructionPlugin_Plane::ID());
-
-  aSession->finishOperation();
-}
-
-void InitializationPlugin_OriginPlanesFeature
-::createPoint(const std::shared_ptr<ModelAPI_Document>& aDoc)
-{
-  std::shared_ptr<ModelAPI_Feature> aPoint = aDoc->addFeature("Point");
-  aPoint->real("x")->setValue(0.);
-  aPoint->real("y")->setValue(0.);
-  aPoint->real("z")->setValue(0.);
-}
diff --git a/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h b/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h
deleted file mode 100644 (file)
index 7b98500..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-#ifndef INITIALIZATIONPLUGIN_ORIGINPLANESFEATURE_H_
-#define INITIALIZATIONPLUGIN_ORIGINPLANESFEATURE_H_
-
-#include <InitializationPlugin.h>
-#include <ModelAPI_Feature.h>
-
-#include <map>
-
-class InitializationPlugin_OriginPlanesFeature : public ModelAPI_Feature
-{
- public:
-  explicit InitializationPlugin_OriginPlanesFeature();
-  virtual ~InitializationPlugin_OriginPlanesFeature();
-  /// Extrusion kind
-  inline static const std::string& ID()
-  {
-    static const std::string MY_ORIGIN_PLANES_ID("OriginAndPlanes");
-    return MY_ORIGIN_PLANES_ID;
-  }
-
-  INITIALIZATIONPLUGIN_EXPORT virtual const std::string& getKind()
-  {
-    static std::string MY_KIND = InitializationPlugin_OriginPlanesFeature::ID();
-    return MY_KIND;
-  }
-
-  INITIALIZATIONPLUGIN_EXPORT virtual void initAttributes();
-
-  INITIALIZATIONPLUGIN_EXPORT virtual void execute();
-
-  INITIALIZATIONPLUGIN_EXPORT virtual bool isInHistory()
-  {
-    return false;
-  }
-
- protected:
-  void createPoint(const std::shared_ptr<ModelAPI_Document>& aDoc);
-};
-
-#endif /* IMPORT_IMPORTFEATURE_H_ */
index 157625b62a492deaed0e4dabd29457ccec99f149..fce2a1a2d8df17ee50abaf0649ec92396b485464 100644 (file)
@@ -2,12 +2,24 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 #include <InitializationPlugin_Plugin.h>
-#include <InitializationPlugin_OriginPlanesFeature.h>
 
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
+
+
+#include <Events_Message.h>
+
+#include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
 
 #include <memory>
 
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
 // the only created instance of this plugin
 static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin();
 
@@ -16,13 +28,60 @@ InitializationPlugin_Plugin::InitializationPlugin_Plugin()
   // register this plugin
   SessionPtr aSession = ModelAPI_Session::get();
   aSession->registerPlugin(this);
+
+  Events_Loop* aLoop = Events_Loop::loop();
+  const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
+  aLoop->registerListener(this, kDocCreatedEvent, NULL, true);
 }
 
 FeaturePtr InitializationPlugin_Plugin::createFeature(std::string theFeatureID)
 {
-  if(InitializationPlugin_OriginPlanesFeature::ID() == theFeatureID) {
-    return FeaturePtr(new InitializationPlugin_OriginPlanesFeature);
-  }
   return FeaturePtr();
 }
 
+void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+  const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId();
+  if (theMessage->eventID() == kDocCreatedEvent) {
+    std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage =
+        std::dynamic_pointer_cast<ModelAPI_DocumentCreatedMessage>(theMessage);
+    DocumentPtr aDoc = aMessage->document();
+    createPoint(aDoc);
+    createPlane(aDoc, 1., 0., 0.);
+    createPlane(aDoc, 0., 1., 0.);
+    createPlane(aDoc, 0., 0., 1.);
+  } else if (theMessage.get()) {
+    #ifdef _DEBUG
+    std::cout << "InitializationPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
+              << theMessage->eventID().eventText() << std::endl;
+    #endif
+  }
+}
+
+void InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theA, double theB, double theC)
+{
+  std::shared_ptr<ModelAPI_Feature> aPlane = theDoc->addFeature("Plane");
+  aPlane->string("CreationMethod")->setValue("PlaneByGeneralEquation");
+  aPlane->real("A")->setValue(theA);
+  aPlane->real("B")->setValue(theB);
+  aPlane->real("C")->setValue(theC);
+  aPlane->real("D")->setValue(0.);
+
+  if (theA) {
+    aPlane->data()->setName("Y0Z");
+  } else if (theB) {
+    aPlane->data()->setName("X0Z");
+  } else if (theC) {
+    aPlane->data()->setName("X0Y");
+  }
+}
+
+void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
+{
+  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");
+}
+
index dfa0727b817b78588709fc6f9ca2bcea31d30163..bd5c1a2198fea7af006835a1a2a95bd728e199e0 100644 (file)
@@ -5,20 +5,27 @@
 #define INITIALIZATIONPLUGIN_PLUGIN_H_
 
 #include <InitializationPlugin.h>
+
 #include <ModelAPI_Plugin.h>
 #include <ModelAPI_Feature.h>
 
+#include <Events_Loop.h>
+
 /**\class InitializationPlugin_Plugin
  * TODO: Add documentation
  */
-class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public ModelAPI_Plugin
+class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public ModelAPI_Plugin,
+                                                                public Events_Listener
 {
  public:
+  InitializationPlugin_Plugin();
+  ~InitializationPlugin_Plugin() {}
   /// Creates the feature object of this plugin by the feature string ID
   virtual FeaturePtr createFeature(std::string theFeatureID);
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
- public:
-  InitializationPlugin_Plugin();
+  void createPlane(DocumentPtr theDoc, double theA, double theB, double theC);
+  void createPoint(DocumentPtr theDoc);
 };
 
 #endif
diff --git a/src/InitializationPlugin/plugin-Initialization.xml b/src/InitializationPlugin/plugin-Initialization.xml
deleted file mode 100644 (file)
index ccd8442..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-<plugin>
-  <workbench id="Features">
-    <group id="Basic">
-      <!-- <feature id="OriginAndPlanes" title="Add default planes" tooltip="Do not touch" icon=":pictures/wnd_close.png"> -->
-      <feature id="OriginAndPlanes" internal="true">
-      </feature>
-    </group>
-  </workbench>
-</plugin>
index 128f6ee4dffa76228158d713d4a5967ffabb6d8b..f8955ce59d5da228b8bd276828f1a1a914f6a964 100644 (file)
@@ -7,6 +7,8 @@
 #include <Model_Application.h>
 #include <Model_Document.h>
 
+#include <ModelAPI_Events.h>
+
 IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
 IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
 
@@ -31,6 +33,12 @@ const std::shared_ptr<Model_Document>& Model_Application::getDocument(string the
   std::shared_ptr<Model_Document> aNew(
     new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind));
   myDocs[theDocID] = aNew;
+
+  Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId();
+  std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage =
+        std::shared_ptr<ModelAPI_DocumentCreatedMessage>(new ModelAPI_DocumentCreatedMessage(anId, this));
+  aMessage->setDocument(aNew);
+  Events_Loop::loop()->send(aMessage);
   // load it if it must be loaded by demand
   if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
     aNew->load(myPath.c_str());
index 2c32f0467ca08193e9a33f916d8e0796e3e42522..51eba966c182977e5787340582512cc134b426e3 100644 (file)
@@ -67,8 +67,11 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   static const Events_ID kOpStartEvent = aLoop->eventByName("StartOperation");
   bool isAutomaticChanged = false;
   if (theMessage->eventID() == kChangedEvent) { // automatic and manual rebuild flag is changed
-    isAutomatic = 
-      Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
+    bool aPropVal = 
+    Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
+    if (aPropVal == isAutomatic)
+      return;// nothing to
+    isAutomatic = aPropVal;
   } else if (theMessage->eventID() == kRebuildEvent) { // the rebuild command
     if (isAutomatic == false) {
       isAutomaticChanged = true;