]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Very first implementation of shape-result management
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 2 Jun 2014 15:41:08 +0000 (19:41 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 2 Jun 2014 15:41:08 +0000 (19:41 +0400)
13 files changed:
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI.i
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h [new file with mode: 0644]
src/Model/CMakeLists.txt
src/Model/Model_AttributeBoolean.cpp
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_Data.h
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_ViewerProxy.h

index ab34919147ff1251a53a238fd62bec0a005e75ec..dc32be9876c22203738ac932552f1a2d68671448 100644 (file)
@@ -15,10 +15,12 @@ SET(PROJECT_SOURCES
 
 ADD_DEFINITIONS(-DCONSTRUCTIONPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
 ADD_LIBRARY(ConstructionPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI)
+TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI)
 
 INCLUDE_DIRECTORIES(
   ../ModelAPI
+  ../GeomAPI
+  ../GeomAlgoAPI
 )
 
 SET(XML_RESOURCES
index ea613603b9d3a3417b05e78da8bdeb6841ad5db6..aaa697dd5684f8c58d26b222f5e798a932ce3357 100644 (file)
@@ -7,6 +7,8 @@
 #include "ModelAPI_Document.h"
 #include "ModelAPI_Data.h"
 #include "ModelAPI_AttributeDouble.h"
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAPI_Pnt.h>
 
 using namespace std;
 
@@ -21,11 +23,10 @@ void ConstructionPlugin_Point::initAttributes()
   data()->addAttribute(POINT_ATTR_Z, ModelAPI_AttributeDouble::type());
 }
 
-// this is for debug only
-#include <iostream>
 void ConstructionPlugin_Point::execute() 
 {
-  // TODO: create a real shape for the point using OCC layer
-  cout<<"X="<<data()->real(POINT_ATTR_X)->value()<<" Y="<<data()->real(POINT_ATTR_Y)->value()
-      <<" Z="<<data()->real(POINT_ATTR_Z)->value()<<endl;
+  boost::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
+    data()->real(POINT_ATTR_X)->value(), data()->real(POINT_ATTR_Y)->value(), data()->real(POINT_ATTR_Z)->value()));
+
+  data()->store(GeomAlgoAPI_PointBuilder::point(aPnt));
 }
index 509c7fd9e0bc5ab7b01c1f3dc608e14e237709ab..db0ae8cb3b611295be57be870b04d7eb5c55d72c 100644 (file)
@@ -9,12 +9,14 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_CompoundBuilder.h
     GeomAlgoAPI_FaceBuilder.h
     GeomAlgoAPI_EdgeBuilder.h
+    GeomAlgoAPI_PointBuilder.h
 )
 
 SET(PROJECT_SOURCES
     GeomAlgoAPI_CompoundBuilder.cpp
     GeomAlgoAPI_FaceBuilder.cpp
     GeomAlgoAPI_EdgeBuilder.cpp
+    GeomAlgoAPI_PointBuilder.cpp
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
index 99a815f744a870d1b0d90f71dd916ad3b3d7f167..c43f350dc4bdb9e9d3471ae71ea82d293bd9cdb4 100644 (file)
@@ -4,6 +4,8 @@
   #include "memory"
   #include "GeomAlgoAPI.h"
   #include "GeomAlgoAPI_FaceBuilder.h"
+  #include "GeomAlgoAPI_EdgeBuilder.h"
+  #include "GeomAlgoAPI_PointBuilder.h"
 %}
 
 // to avoid error on this
@@ -17,3 +19,5 @@
 
 // all supported interfaces
 %include "GeomAlgoAPI_FaceBuilder.h"
+%include "GeomAlgoAPI_EdgeBuilder.h"
+%include "GeomAlgoAPI_PointBuilder.h"
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp
new file mode 100644 (file)
index 0000000..d12bd6a
--- /dev/null
@@ -0,0 +1,22 @@
+// File:        GeomAlgoAPI_PointBuilder.cpp
+// Created:     02 Jun 2014
+// Author:      Mikhail PONIKAROV
+
+
+
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <TopoDS_Vertex.hxx>
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
+    boost::shared_ptr<GeomAPI_Pnt> thePoint)
+{
+  const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
+  BRepBuilderAPI_MakeVertex aMaker(aPnt);
+  TopoDS_Vertex aVertex = aMaker.Vertex();
+  boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+  aRes->setImpl(new TopoDS_Shape(aVertex));
+  return aRes;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h
new file mode 100644 (file)
index 0000000..2715062
--- /dev/null
@@ -0,0 +1,27 @@
+// File:        GeomAlgoAPI_PointBuilder.h
+// Created:     02 Jun 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomAlgoAPI_PointBuilder_HeaderFile
+#define GeomAlgoAPI_PointBuilder_HeaderFile
+
+#include <GeomAlgoAPI.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_Shape;
+class GeomAPI_Pnt;
+
+/**\class GeomAlgoAPI_PointBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder
+{
+public:
+  /// Creates linear edge by two points
+  static boost::shared_ptr<GeomAPI_Shape> point(
+    boost::shared_ptr<GeomAPI_Pnt> thePoint);
+};
+
+#endif
index 9da38b914c666e7dcd6563552f3372e5647f91d3..6b89aac785b85c82fcfdb3016fd0a81cdb53eb85 100644 (file)
@@ -36,7 +36,9 @@ SET(PROJECT_LIBRARIES
     Events 
     Config 
     GeomData
+    GeomAPI
     ${CAS_OCAF}
+    ${CAS_TKCAF}
 )
 
 
@@ -51,6 +53,7 @@ INCLUDE_DIRECTORIES(
   ../Config
   ../GeomData
   ../GeomDataAPI
+  ../GeomAPI
   ${CAS_INCLUDE_DIRS}
 )
 
index d3c0d6bc5aa9f5950f229b09bbc9d5a06549d53b..5472dadf255f13feac8b09704726979751f0d191 100644 (file)
@@ -10,8 +10,9 @@ using namespace std;
 
 void Model_AttributeBoolean::setValue(bool theValue)
 {
-  if (myBool->Get() != theValue) {
-    myBool->Set(theValue? 1 : 0);
+  Standard_Boolean aValue = theValue ? Standard_True : Standard_False;
+  if (myBool->Get() != aValue) {
+    myBool->Set(aValue);
     static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
     Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
     Events_Loop::loop()->send(aMsg);
@@ -20,7 +21,7 @@ void Model_AttributeBoolean::setValue(bool theValue)
 
 bool Model_AttributeBoolean::value()
 {
-  return (myBool->Get() == 1)? true : false;
+  return myBool->Get() == Standard_True;
 }
 
 Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
index f794bda07c143f0936ff573d656542285969b459..ee81944226cff7f0e24914eb285d56973459cabc 100644 (file)
@@ -188,3 +188,34 @@ bool Model_Data::isValid()
 {
   return !myLab.IsNull() && myLab.HasAttribute();
 }
+
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
+
+void Model_Data::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
+{
+  // the simplest way is to keep this attribute here, on Data
+  // TODO: add naming structure in separated document for shape storage
+  TNaming_Builder aBuilder(myLab);
+  if (!theShape) return; // bad shape
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  if (aShape.IsNull()) return; // null shape inside
+
+  aBuilder.Generated(aShape);
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_Data::shape()
+{
+  Handle(TNaming_NamedShape) aName;
+  if (myLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
+    TopoDS_Shape aShape = aName->Get();
+    if (!aShape.IsNull()) {
+      boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+      aRes->setImpl(new TopoDS_Shape(aShape));
+      return aRes;
+    }
+  }
+  return boost::shared_ptr<GeomAPI_Shape>();
+}
index 03ff0c54eddc44dd8fec9cf433b9cfa307edb9b5..deb7239a583913e9bb0dafdfd422ed0031a89518 100644 (file)
@@ -68,6 +68,11 @@ public:
   /// Returns true if it is correctly connected t othe data model
   MODEL_EXPORT virtual bool isValid();
 
+  /// Stores the shape (called by the execution method).
+  MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+  /// Returns the shape-result produced by this feature
+  MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
+
   /// Initializes object by the attributes: must be called just after the object is created
   /// for each attribute of the object
   /// \param theID identifier of the attribute that can be referenced by this ID later
index f8dd2289673e932f53d9d01a26df8e5acee9c17b..3bae7c023be864d8134b40e4b08206a8567ddb5e 100644 (file)
@@ -16,6 +16,7 @@ class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeRefList;
 class ModelAPI_Document;
 class ModelAPI_Attribute;
+class GeomAPI_Shape;
 
 /**\class ModelAPI_Data
  * \ingroup DataModel
@@ -55,6 +56,11 @@ public:
   /// Returns true if it is correctly connected t othe data model
   virtual bool isValid() = 0;
 
+  /// Stores the shape (called by the execution method).
+  virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+  /// Returns the shape-result produced by this feature
+  virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;
+
   /// Initializes object by the attributes: must be called just after the object is created
   /// for each attribute of the object
   /// \param theID identifier of the attribute that can be referenced by this ID later
index 739edf06aa50094abdefee6a0e3fca18987e89d0..e9bba754fc817fde2dd8e747ec6310b283d5a8bf 100644 (file)
@@ -315,7 +315,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
 
   // create the operation
-  ModuleBase_Operation* anOperation;
+  ModuleBase_Operation* anOperation = 0;
   if (theCmdId == PartSet_OperationSketch::Type()) {
     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
   }
index 1f7f63344662da2dfef8de75ebc948c303a4e4fc..dfd632bdab9699a1497f78fcdca15e941d36f6c7 100644 (file)
@@ -64,4 +64,4 @@ private:
   XGUI_Workshop* myWorkshop;
 };
 
-#endif
\ No newline at end of file
+#endif