From: mpv Date: Mon, 2 Jun 2014 15:41:08 +0000 (+0400) Subject: Very first implementation of shape-result management X-Git-Tag: V_0.4.4~334^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d9db580f9120174f43a7dc0d3b8843d614ced62c;p=modules%2Fshaper.git Very first implementation of shape-result management --- diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index ab3491914..dc32be987 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -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 diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index ea613603b..aaa697dd5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -7,6 +7,8 @@ #include "ModelAPI_Document.h" #include "ModelAPI_Data.h" #include "ModelAPI_AttributeDouble.h" +#include +#include 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 void ConstructionPlugin_Point::execute() { - // TODO: create a real shape for the point using OCC layer - cout<<"X="<real(POINT_ATTR_X)->value()<<" Y="<real(POINT_ATTR_Y)->value() - <<" Z="<real(POINT_ATTR_Z)->value()< 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)); } diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 509c7fd9e..db0ae8cb3 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -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}) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i index 99a815f74..c43f350dc 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI.i +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -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 index 000000000..d12bd6a86 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -0,0 +1,22 @@ +// File: GeomAlgoAPI_PointBuilder.cpp +// Created: 02 Jun 2014 +// Author: Mikhail PONIKAROV + + + +#include +#include +#include +#include +#include + +boost::shared_ptr GeomAlgoAPI_PointBuilder::point( + boost::shared_ptr thePoint) +{ + const gp_Pnt& aPnt = thePoint->impl(); + BRepBuilderAPI_MakeVertex aMaker(aPnt); + TopoDS_Vertex aVertex = aMaker.Vertex(); + boost::shared_ptr 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 index 000000000..2715062bb --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h @@ -0,0 +1,27 @@ +// File: GeomAlgoAPI_PointBuilder.h +// Created: 02 Jun 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAlgoAPI_PointBuilder_HeaderFile +#define GeomAlgoAPI_PointBuilder_HeaderFile + +#include +#include + +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 point( + boost::shared_ptr thePoint); +}; + +#endif diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 9da38b914..6b89aac78 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -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} ) diff --git a/src/Model/Model_AttributeBoolean.cpp b/src/Model/Model_AttributeBoolean.cpp index d3c0d6bc5..5472dadf2 100644 --- a/src/Model/Model_AttributeBoolean.cpp +++ b/src/Model/Model_AttributeBoolean.cpp @@ -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) diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index f794bda07..ee8194422 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -188,3 +188,34 @@ bool Model_Data::isValid() { return !myLab.IsNull() && myLab.HasAttribute(); } + +#include +#include +#include +#include + +void Model_Data::store(const boost::shared_ptr& 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(); + if (aShape.IsNull()) return; // null shape inside + + aBuilder.Generated(aShape); +} + +boost::shared_ptr 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 aRes(new GeomAPI_Shape); + aRes->setImpl(new TopoDS_Shape(aShape)); + return aRes; + } + } + return boost::shared_ptr(); +} diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 03ff0c54e..deb7239a5 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -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& theShape); + /// Returns the shape-result produced by this feature + MODEL_EXPORT virtual boost::shared_ptr 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 diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index f8dd22896..3bae7c023 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -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& theShape) = 0; + /// Returns the shape-result produced by this feature + virtual boost::shared_ptr 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 diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 739edf06a..e9bba754f 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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); } diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index 1f7f63344..dfd632bda 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -64,4 +64,4 @@ private: XGUI_Workshop* myWorkshop; }; -#endif \ No newline at end of file +#endif