--- /dev/null
-shared_ptr<ModelAPI_Feature> ConstructionPlugin_Plugin::createFeature(string theFeatureID)
+ #include "ConstructionPlugin_Plugin.h"
+ #include "ConstructionPlugin_Point.h"
+ #include <ModelAPI_PluginManager.h>
+ #include <ModelAPI_Document.h>
+
+ using namespace std;
+
+ // the only created instance of this plugin
+ static ConstructionPlugin_Plugin* MY_INSTANCE = new ConstructionPlugin_Plugin();
+
+ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
+ {
+ // register this plugin
+ ModelAPI_PluginManager::get()->registerPlugin(this);
+ }
+
- return shared_ptr<ModelAPI_Feature>(new ConstructionPlugin_Point);
++boost::shared_ptr<ModelAPI_Feature> ConstructionPlugin_Plugin::createFeature(string theFeatureID)
+ {
+ if (theFeatureID == "Point") {
- return shared_ptr<ModelAPI_Feature>();
++ return boost::shared_ptr<ModelAPI_Feature>(new ConstructionPlugin_Point);
+ }
+ // feature of such kind is not found
++ return boost::shared_ptr<ModelAPI_Feature>();
+ }
--- /dev/null
- #include "memory"
+ /* GeomAPI.i */
+ %module GeomAPI
+ %{
-%include <std_shared_ptr.i>
++ #include "boost/shared_ptr.hpp"
+ #include "GeomAPI.h"
+ #include "GeomAPI_Interface.h"
+ #include "GeomAPI_Pnt.h"
+ #include "GeomAPI_Shape.h"
+ %}
+
+ // to avoid error on this
+ #define GEOMAPI_EXPORT
+
+ // standard definitions
+ %include "typemaps.i"
+ %include "std_string.i"
++//%include <std_shared_ptr.i>
++%include <boost_shared_ptr.i>
+
+ // boost pointers
+ // %include <boost_shared_ptr.i>
+ %shared_ptr(GeomAPI_Interface)
+ %shared_ptr(GeomAPI_Pnt)
+ %shared_ptr(GeomAPI_Shape)
+
+ // all supported interfaces
+ %include "GeomAPI_Interface.h"
+ %include "GeomAPI_Pnt.h"
+ %include "GeomAPI_Shape.h"
--- /dev/null
-%include <std_shared_ptr.i>
+ /* GeomAPI.i */
+ %module GeomAlgoAPI
+ %{
+ #include "memory"
+ #include "GeomAlgoAPI.h"
+ #include "GeomAlgoAPI_FaceBuilder.h"
+ %}
+
+ // to avoid error on this
+ #define GEOMALGOAPI_EXPORT
+
+ // standard definitions
+ %include "typemaps.i"
+ %include "std_string.i"
++//%include <std_shared_ptr.i>
++%include <boost_shared_ptr.i>
+
+ // all supported interfaces
+ %include "GeomAlgoAPI_FaceBuilder.h"
--- /dev/null
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
- std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
+ // File: GeomAlgoAPI_FaceBuilder.cpp
+ // Created: 23 Apr 2014
+ // Author: Mikhail PONIKAROV
+
+ #include <GeomAlgoAPI_FaceBuilder.h>
+ #include <gp_Pln.hxx>
+ #include <BRepBuilderAPI_MakeFace.hxx>
+ #include <TopoDS_Face.hxx>
+
- std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
++boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
++ boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Dir> theNormal,
+ const double theSize)
+ {
+ gp_Pnt* aCenter = static_cast<gp_Pnt*>(theCenter->implementation());
+ gp_Dir* aDir = static_cast<gp_Dir*>(theNormal->implementation());
+ gp_Pln aPlane(*aCenter, *aDir);
+ // half of the size in each direction from the center
+ BRepBuilderAPI_MakeFace aFaceBuilder(aPlane,
+ -theSize / 2., theSize / 2., -theSize / 2., theSize / 2.);
++ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImplementation(new TopoDS_Shape(aFaceBuilder.Face()));
+ return aRes;
+ }
--- /dev/null
-#include <memory>
+ // File: GeomAlgoAPI_FaceBuilder.h
+ // Created: 23 Apr 2014
+ // Author: Mikhail PONIKAROV
+
+ #ifndef GeomAlgoAPI_FaceBuilder_HeaderFile
+ #define GeomAlgoAPI_FaceBuilder_HeaderFile
+
+ #include <GeomAlgoAPI.h>
+ #include <GeomAPI_Shape.h>
+ #include <GeomAPI_Pnt.h>
+ #include <GeomAPI_Dir.h>
- static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pnt> theCenter,
- std::shared_ptr<GeomAPI_Dir> theNormal, const double theSize);
++#include <boost/shared_ptr.hpp>
+
+ /**\class GeomAlgoAPI_FaceBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder
+ {
+ public:
+ /// Creates square planar face by given point of the center,
+ /// normal to the plane and size of square
++ static boost::shared_ptr<GeomAPI_Shape> square(boost::shared_ptr<GeomAPI_Pnt> theCenter,
++ boost::shared_ptr<GeomAPI_Dir> theNormal, const double theSize);
+ };
+
+ #endif
)
SET(PROJECT_SOURCES
- Model_Application.cxx
- Model_Document.cxx
- Model_PluginManager.cxx
- Model_Data.cxx
- Model_Iterator.cxx
- Model_AttributeDouble.cxx
- Model_AttributeDocRef.cxx
- Model_Events.cxx
+ Model_Application.cpp
+ Model_Document.cpp
+ Model_PluginManager.cpp
+ Model_Data.cpp
+ Model_Iterator.cpp
+ Model_AttributeDouble.cpp
+ Model_AttributeDocRef.cpp
+ Model_Events.cpp
)
-ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS})
+ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Event Config)
--- /dev/null
-const std::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
+ // File: Model_Application.cxx
+ // Created: Fri Sep 2 2011
+ // Author: Mikhail PONIKAROV
+
+ #include <Model_Application.h>
+ #include <Model_Document.h>
+
+ IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
+ IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
+
+ using namespace std;
+
+ static Handle_Model_Application TheApplication = new Model_Application;
+
+ //=======================================================================
+ Handle(Model_Application) Model_Application::getApplication()
+ {
+ return TheApplication;
+ }
+
+ //=======================================================================
- std::shared_ptr<Model_Document> aNew(new Model_Document(theDocID));
++const boost::shared_ptr<Model_Document>& Model_Application::getDocument(string theDocID)
+ {
+ if (myDocs.find(theDocID) != myDocs.end())
+ return myDocs[theDocID];
+
++ boost::shared_ptr<Model_Document> aNew(new Model_Document(theDocID));
+ myDocs[theDocID] = aNew;
+ return myDocs[theDocID];
+ }
+
+ void Model_Application::deleteDocument(string theDocID)
+ {
+ myDocs.erase(theDocID);
+ }
+
+ //=======================================================================
+ bool Model_Application::hasDocument(std::string theDocID)
+ {
+ return myDocs.find(theDocID) != myDocs.end();
+ }
+
+ //=======================================================================
+ Model_Application::Model_Application()
+ {
+ // store handle to the application to avoid nullification
+ static Handle(Model_Application) TheKeepHandle;
+ TheKeepHandle = this;
+ }
+
+ //=======================================================================
+ void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
+ {
+ theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema
+ }
+
+ //=======================================================================
+ Standard_CString Model_Application::ResourcesName()
+ {
+ return Standard_CString("Standard");
+ }
--- /dev/null
-void Model_AttributeDocRef::setValue(std::shared_ptr<ModelAPI_Document> theDoc)
+ // File: ModelAPI_AttributeDocRef.cxx
+ // Created: 2 Apr 2014
+ // Author: Mikhail PONIKAROV
+
+ #include "Model_AttributeDocRef.h"
+ #include "Model_Application.h"
+
+ using namespace std;
+
-std::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
++void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
+ {
+ myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
+ }
+
- return std::shared_ptr<ModelAPI_Document>();
++boost::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
+ {
+ if (myComment->Get().Length())
+ return Model_Application::getApplication()->getDocument(
+ TCollection_AsciiString(myComment->Get()).ToCString());
+ // not initialized
++ return boost::shared_ptr<ModelAPI_Document>();
+ }
+
+ Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
+ {
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment)) {
+ // create attribute: not initialized by value yet, just empty string
+ myComment = TDataStd_Comment::Set(theLabel, "");
+ }
+ }
--- /dev/null
- myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
+ // File: Model_Data.hxx
+ // Created: 21 Mar 2014
+ // Author: Mikhail PONIKAROV
+
+ #include <Model_Data.h>
+ #include <Model_AttributeDocRef.h>
+ #include <Model_AttributeDouble.h>
+ #include <TDataStd_Name.hxx>
+
+ using namespace std;
+
+ Model_Data::Model_Data()
+ {
+ }
+
+ void Model_Data::setLabel(TDF_Label& theLab)
+ {
+ myLab = theLab;
+ }
+
+ string Model_Data::getName()
+ {
+ Handle(TDataStd_Name) aName;
+ if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
+ return string(TCollection_AsciiString(aName->Get()).ToCString());
+ return ""; // not defined
+ }
+
+ void Model_Data::setName(string theName)
+ {
+ TDataStd_Name::Set(myLab, theName.c_str());
+ }
+
+ void Model_Data::addAttribute(string theID, string theAttrType)
+ {
+ TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
+ ModelAPI_Attribute* anAttr = 0;
+ if (theAttrType == ModelAPI_AttributeDocRef::type())
+ anAttr = new Model_AttributeDocRef(anAttrLab);
+ else if (theAttrType == ModelAPI_AttributeDouble::type())
+ anAttr = new Model_AttributeDouble(anAttrLab);
+
+ if (anAttr)
-shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
++ myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
+ else
+ ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ }
+
- map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
++boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
+ {
- return std::shared_ptr<ModelAPI_AttributeDocRef>();
++ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
- shared_ptr<ModelAPI_AttributeDocRef> aRes =
- dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
++ return boost::shared_ptr<ModelAPI_AttributeDocRef>();
+ }
-shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
++ boost::shared_ptr<ModelAPI_AttributeDocRef> aRes =
++ boost::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+ }
+
- map<string, shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
++boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
+ {
- return std::shared_ptr<ModelAPI_AttributeDouble>();
++ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
- shared_ptr<ModelAPI_AttributeDouble> aRes =
- dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
++ return boost::shared_ptr<ModelAPI_AttributeDouble>();
+ }
++ boost::shared_ptr<ModelAPI_AttributeDouble> aRes =
++ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+ }
--- /dev/null
-shared_ptr<ModelAPI_Feature> Model_Document::addFeature(string theID)
+ // File: Model_Document.cxx
+ // Created: 28 Feb 2014
+ // Author: Mikhail PONIKAROV
+
+ #include <Model_Document.h>
+ #include <ModelAPI_Feature.h>
+ #include <Model_Data.h>
+ #include <Model_Application.h>
+ #include <Model_PluginManager.h>
+ #include <Model_Iterator.h>
+ #include <Model_Events.h>
+ #include <Event_Loop.h>
+
+ #include <TDataStd_Integer.hxx>
+ #include <TDataStd_Comment.hxx>
+ #include <TDF_ChildIDIterator.hxx>
+
+ #include <climits>
+
+ static const int UNDO_LIMIT = 10; // number of possible undo operations
+
+ static const int TAG_GENERAL = 1; // general properties tag
+ static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (Root for Model_DatasMgr)
+ static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for Model_History)
+
+ using namespace std;
+
+ bool Model_Document::load(const char* theFileName)
+ {
+ bool myIsError = Standard_False;
+ /*
+ TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
+ PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
+ try
+ {
+ Handle(TDocStd_Document) aDoc = this;
+ aStatus = Model_Application::GetApplication()->Open(aPath, aDoc);
+ }
+ catch (Standard_Failure)
+ {}
+ myIsError = aStatus != PCDM_RS_OK;
+ if (myIsError)
+ {
+ switch (aStatus)
+ {
+ case PCDM_RS_UnknownDocument: cout<<"OCAFApp_Appl_RUnknownDocument"<<endl; break;
+ case PCDM_RS_AlreadyRetrieved: cout<<"OCAFApp_Appl_RAlreadyRetrieved"<<endl; break;
+ case PCDM_RS_AlreadyRetrievedAndModified: cout<<"OCAFApp_Appl_RAlreadyRetrievedAndModified"<<endl; break;
+ case PCDM_RS_NoDriver: cout<<"OCAFApp_Appl_RNoDriver"<<endl; break;
+ case PCDM_RS_UnknownFileDriver: cout<<"OCAFApp_Appl_RNoDriver"<<endl; break;
+ case PCDM_RS_OpenError: cout<<"OCAFApp_Appl_ROpenError"<<endl; break;
+ case PCDM_RS_NoVersion: cout<<"OCAFApp_Appl_RNoVersion"<<endl; break;
+ case PCDM_RS_NoModel: cout<<"OCAFApp_Appl_RNoModel"<<endl; break;
+ case PCDM_RS_NoDocument: cout<<"OCAFApp_Appl_RNoDocument"<<endl; break;
+ case PCDM_RS_FormatFailure: cout<<"OCAFApp_Appl_RFormatFailure"<<endl; break;
+ case PCDM_RS_TypeNotFoundInSchema: cout<<"OCAFApp_Appl_RTypeNotFound"<<endl; break;
+ case PCDM_RS_UnrecognizedFileFormat: cout<<"OCAFApp_Appl_RBadFileFormat"<<endl; break;
+ case PCDM_RS_MakeFailure: cout<<"OCAFApp_Appl_RMakeFailure"<<endl; break;
+ case PCDM_RS_PermissionDenied: cout<<"OCAFApp_Appl_RPermissionDenied"<<endl; break;
+ case PCDM_RS_DriverFailure: cout<<"OCAFApp_Appl_RDriverFailure"<<endl; break;
+ default: cout<<"OCAFApp_Appl_RUnknownFail"<<endl; break;
+ }
+ }
+ SetUndoLimit(UNDO_LIMIT);
+ */
+ return !myIsError;
+ }
+
+ bool Model_Document::save(const char* theFileName)
+ {
+ bool myIsError = true;
+ /*
+ TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
+ PCDM_StoreStatus aStatus;
+ try {
+ Handle(TDocStd_Document) aDoc = this;
+ aStatus = Model_Application::GetApplication()->SaveAs (aDoc, aPath);
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ cout<<"OCAFApp_Engine:save Error: "<<aFail->GetMessageString()<<endl;
+ return false;
+ }
+ myIsError = aStatus != PCDM_SS_OK;
+ if (myIsError)
+ {
+ switch (aStatus)
+ {
+ case PCDM_SS_DriverFailure:
+ cout<<"OCAFApp_Appl_SDriverFailure"<<endl;
+ break;
+ case PCDM_SS_WriteFailure:
+ cout<<"OCAFApp_Appl_SWriteFailure"<<endl;
+ break;
+ case PCDM_SS_Failure:
+ default:
+ cout<<"OCAFApp_Appl_SUnknownFailure"<<endl;
+ break;
+ }
+ }
+ myTransactionsAfterSave = 0;
+ Standard::Purge(); // Release free memory
+ */
+ return !myIsError;
+ }
+
+ void Model_Document::close()
+ {
+ // close all subs
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ subDocument(*aSubIter)->close();
+ mySubs.clear();
+ // close this
+ myDoc->Close();
+ Model_Application::getApplication()->deleteDocument(myID);
+ }
+
+ void Model_Document::startOperation()
+ {
+ // new command for this
+ myDoc->NewCommand();
+ // new command for all subs
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ subDocument(*aSubIter)->startOperation();
+ }
+
+ void Model_Document::finishOperation()
+ {
+ // returns false if delta is empty and no transaction was made
+ myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand();
+ myTransactionsAfterSave++;
+ // finish for all subs
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ subDocument(*aSubIter)->finishOperation();
+ }
+
+ void Model_Document::abortOperation()
+ {
+ myDoc->AbortCommand();
+ // abort for all subs
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ subDocument(*aSubIter)->abortOperation();
+ }
+
+ bool Model_Document::isOperation()
+ {
+ // operation is opened for all documents: no need to check subs
+ return myDoc->HasOpenCommand() == Standard_True ;
+ }
+
+ bool Model_Document::isModified()
+ {
+ // is modified if at least one operation was commited and not undoed
+ return myTransactionsAfterSave > 0;
+ }
+
+ bool Model_Document::canUndo()
+ {
+ if (myDoc->GetAvailableUndos() > 0)
+ return true;
+ // check other subs contains operation that can be undoed
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ if (subDocument(*aSubIter)->canUndo())
+ return true;
+ return false;
+ }
+
+ void Model_Document::undo()
+ {
+ myTransactionsAfterSave--;
+ if (!myIsEmptyTr[myTransactionsAfterSave])
+ myDoc->Undo();
+ synchronizeFeatures();
+ // undo for all subs
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ subDocument(*aSubIter)->undo();
+ }
+
+ bool Model_Document::canRedo()
+ {
+ if (myDoc->GetAvailableRedos() > 0)
+ return true;
+ // check other subs contains operation that can be redoed
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ if (subDocument(*aSubIter)->canRedo())
+ return true;
+ return false;
+ }
+
+ void Model_Document::redo()
+ {
+ if (!myIsEmptyTr[myTransactionsAfterSave])
+ myDoc->Redo();
+ myTransactionsAfterSave++;
+ synchronizeFeatures();
+ // redo for all subs
+ set<string>::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++)
+ subDocument(*aSubIter)->redo();
+ }
+
- shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
++boost::shared_ptr<ModelAPI_Feature> Model_Document::addFeature(string theID)
+ {
- dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd())->addFeature(aFeature);
++ boost::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
+ if (aFeature) {
-void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeature)
++ boost::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd())->addFeature(aFeature);
+ } else {
+ // TODO: generate error that feature is not created
+ }
+ return aFeature;
+ }
+
- std::shared_ptr<Model_Data> aData(new Model_Data);
++void Model_Document::addFeature(const boost::shared_ptr<ModelAPI_Feature> theFeature)
+ {
+ const std::string& aGroup = theFeature->getGroup();
+ TDF_Label aGroupLab = groupLabel(aGroup);
+ TDF_Label anObjLab = aGroupLab.NewChild();
- shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
++ boost::shared_ptr<Model_Data> aData(new Model_Data);
+ aData->setLabel(anObjLab);
-shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
++ boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
+ aData->setDocument(aThis);
+ theFeature->setData(aData);
+ setUniqueName(theFeature);
+ theFeature->initAttributes();
+ // keep the feature ID to restore document later correctly
+ TDataStd_Comment::Set(anObjLab, theFeature->getKind().c_str());
+ // put index of the feature in the group in the tree
+ TDataStd_Integer::Set(anObjLab, myFeatures[aGroup].size());
+ myFeatures[aGroup].push_back(theFeature);
+
+ // event: feature is added
+ static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
+ ModelAPI_FeatureUpdatedMessage aMsg(aThis, theFeature, anEvent);
+ Event_Loop::loop()->send(aMsg);
+ }
+
- return std::shared_ptr<ModelAPI_Feature>(); // not found
++boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
+ {
+ Handle(TDataStd_Integer) aFeatureIndex;
+ if (theLabel.FindAttribute(TDataStd_Integer::GetID(), aFeatureIndex)) {
+ Handle(TDataStd_Comment) aGroupID;
+ if (theLabel.Father().FindAttribute(TDataStd_Comment::GetID(), aGroupID)) {
+ string aGroup = TCollection_AsciiString(aGroupID->Get()).ToCString();
+ return myFeatures[aGroup][aFeatureIndex->Get()];
+ }
+ }
-int Model_Document::featureIndex(shared_ptr<ModelAPI_Feature> theFeature)
++ return boost::shared_ptr<ModelAPI_Feature>(); // not found
+ }
+
- shared_ptr<Model_Data> aData = dynamic_pointer_cast<Model_Data>(theFeature->data());
++int Model_Document::featureIndex(boost::shared_ptr<ModelAPI_Feature> theFeature)
+ {
+ if (theFeature->data()->document().get() != this) {
+ return theFeature->data()->document()->featureIndex(theFeature);
+ }
-shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
++ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ Handle(TDataStd_Integer) aFeatureIndex;
+ if (aData->label().FindAttribute(TDataStd_Integer::GetID(), aFeatureIndex)) {
+ return aFeatureIndex->Get();
+ }
+ return -1; // not found
+ }
+
-shared_ptr<ModelAPI_Iterator> Model_Document::featuresIterator(const string theGroup)
++boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
+ {
+ // just store sub-document identifier here to manage it later
+ if (mySubs.find(theDocID) == mySubs.end())
+ mySubs.insert(theDocID);
+ return Model_Application::getApplication()->getDocument(theDocID);
+ }
+
- shared_ptr<Model_Document> aThis(Model_Application::getApplication()->getDocument(myID));
++boost::shared_ptr<ModelAPI_Iterator> Model_Document::featuresIterator(const string theGroup)
+ {
- return shared_ptr<ModelAPI_Iterator>(new Model_Iterator());
- return shared_ptr<ModelAPI_Iterator>(new Model_Iterator(aThis, groupLabel(theGroup)));
++ boost::shared_ptr<Model_Document> aThis(Model_Application::getApplication()->getDocument(myID));
+ // create an empty iterator for not existing group
+ // (to avoidance of attributes management outside the transaction)
+ if (myGroups.find(theGroup) == myGroups.end())
-shared_ptr<ModelAPI_Feature> Model_Document::feature(const string& theGroupID, const int theIndex)
++ return boost::shared_ptr<ModelAPI_Iterator>(new Model_Iterator());
++ return boost::shared_ptr<ModelAPI_Iterator>(new Model_Iterator(aThis, groupLabel(theGroup)));
+ }
+
- shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theGroupID);
++boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(const string& theGroupID, const int theIndex)
+ {
+ // TODO: optimize this method
- return anIter->more() ? anIter->current() : shared_ptr<ModelAPI_Feature>();
++ boost::shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theGroupID);
+ for(int a = 0; a != theIndex && anIter->more(); anIter->next()) a++;
- myFeatures[theGroup] = vector<shared_ptr<ModelAPI_Feature> >();
++ return anIter->more() ? anIter->current() : boost::shared_ptr<ModelAPI_Feature>();
+ }
+
+ const vector<string>& Model_Document::getGroups() const
+ {
+ return myGroupsNames;
+ }
+
+ Model_Document::Model_Document(const std::string theID)
+ : myID(theID), myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
+ {
+ myDoc->SetUndoLimit(UNDO_LIMIT);
+ myTransactionsAfterSave = 0;
+ // to avoid creation of tag outside of the transaction (by iterator, for example)
+ /*
+ if (!myDoc->Main().FindChild(TAG_OBJECTS).IsAttribute(TDF_TagSource::GetID()))
+ TDataStd_Comment::Set(myDoc->Main().FindChild(TAG_OBJECTS).NewChild(), "");
+ */
+ }
+
+ TDF_Label Model_Document::groupLabel(const string theGroup)
+ {
+ if (myGroups.find(theGroup) == myGroups.end()) {
+ myGroups[theGroup] = myDoc->Main().FindChild(TAG_OBJECTS).NewChild();
+ myGroupsNames.push_back(theGroup);
+ // set to the group label the group idntifier to restore on "open"
+ TDataStd_Comment::Set(myGroups[theGroup], theGroup.c_str());
-void Model_Document::setUniqueName(
- shared_ptr<ModelAPI_Feature> theFeature)
++ myFeatures[theGroup] = vector<boost::shared_ptr<ModelAPI_Feature> >();
+ }
+ return myGroups[theGroup];
+ }
+
- shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theFeature->getGroup());
++void Model_Document::setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeature)
+ {
+ // first count all objects of such kind to start with index = count + 1
+ int aNumObjects = 0;
- shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
++ boost::shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theFeature->getGroup());
+ for(; anIter->more(); anIter->next()) {
+ if (anIter->currentKind() == theFeature->getKind())
+ aNumObjects++;
+ }
+ // generate candidate name
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ string aName = aNameStream.str();
+ // check this is unique, if not, increase index by 1
+ for(anIter = featuresIterator(theFeature->getGroup()); anIter->more();) {
+ if (anIter->currentName() == aName) {
+ aNumObjects++;
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ // reinitialize iterator to make sure a new name is unique
+ anIter = featuresIterator(theFeature->getGroup());
+ } else anIter->next();
+ }
+
+ theFeature->data()->setName(aName);
+ }
+
+ void Model_Document::synchronizeFeatures()
+ {
- myFeatures[aGroupName] = vector<shared_ptr<ModelAPI_Feature> >();
++ boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
+ // iterate groups labels
+ TDF_ChildIDIterator aGroupsIter(myDoc->Main().FindChild(TAG_OBJECTS),
+ TDataStd_Comment::GetID(), Standard_False);
+ vector<string>::iterator aGroupNamesIter = myGroupsNames.begin();
+ for(; aGroupsIter.More() && aGroupNamesIter != myGroupsNames.end();
+ aGroupsIter.Next(), aGroupNamesIter++) {
+ string aGroupName = TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
+ aGroupsIter.Value())->Get()).ToCString();
+ if (*aGroupNamesIter != aGroupName)
+ break; // all since there is a change this must be recreated from scratch
+ }
+ // delete all groups left after the data model groups iteration
+ while(aGroupNamesIter != myGroupsNames.end()) {
+ string aGroupName = *aGroupNamesIter;
+ myFeatures.erase(aGroupName);
+ myGroups.erase(aGroupName);
+ aGroupNamesIter = myGroupsNames.erase(aGroupNamesIter);
+ // say that features were deleted from group
+ ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
+ Event_Loop::loop()->send(aMsg);
+ }
+ // create new groups basing on the following data model update
+ for(; aGroupsIter.More(); aGroupsIter.Next()) {
+ string aGroupName = TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
+ aGroupsIter.Value())->Get()).ToCString();
+ myGroupsNames.push_back(aGroupName);
+ myGroups[aGroupName] = aGroupsIter.Value()->Label();
- vector<shared_ptr<ModelAPI_Feature> >& aFeatures = myFeatures[aGroupName];
- vector<shared_ptr<ModelAPI_Feature> >::iterator aFIter = aFeatures.begin();
++ myFeatures[aGroupName] = vector<boost::shared_ptr<ModelAPI_Feature> >();
+ }
+ // update features group by group
+ aGroupsIter.Initialize(myDoc->Main().FindChild(TAG_OBJECTS),
+ TDataStd_Comment::GetID(), Standard_False);
+ for(; aGroupsIter.More(); aGroupsIter.Next()) {
+ string aGroupName = TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
+ aGroupsIter.Value())->Get()).ToCString();
+ // iterate features in internal container
- shared_ptr<Model_Data> aData = dynamic_pointer_cast<Model_Data>((*aFIter)->data());
++ vector<boost::shared_ptr<ModelAPI_Feature> >& aFeatures = myFeatures[aGroupName];
++ vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = aFeatures.begin();
+ // and in parallel iterate labels of features
+ TDF_ChildIDIterator aFLabIter(
+ aGroupsIter.Value()->Label(), TDataStd_Comment::GetID(), Standard_False);
+ while(aFIter != aFeatures.end() || aFLabIter.More()) {
+ static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
+ int aFeatureTag = INFINITE_TAG;
+ if (aFIter != aFeatures.end()) { // existing tag for feature
- shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(
++ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
+ aFeatureTag = aData->label().Tag();
+ }
+ int aDSTag = INFINITE_TAG;
+ if (aFLabIter.More()) { // next label in DS is existing
+ aDSTag = aFLabIter.Value()->Label().Tag();
+ }
+ if (aDSTag > aFeatureTag) { // feature is removed
+ aFIter = aFeatures.erase(aFIter);
+ // event: model is updated
+ ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
+ Event_Loop::loop()->send(aMsg);
+ } else if (aDSTag < aFeatureTag) { // a new feature is inserted
+ // create a feature
- std::shared_ptr<Model_Data> aData(new Model_Data);
++ boost::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(
+ TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
+ aFLabIter.Value())->Get()).ToCString());
+
++ boost::shared_ptr<Model_Data> aData(new Model_Data);
+ TDF_Label aLab = aFLabIter.Value()->Label();
+ aData->setLabel(aLab);
+ aData->setDocument(Model_Application::getApplication()->getDocument(myID));
+ aFeature->setData(aData);
+ aFeature->initAttributes();
+ // event: model is updated
+ static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
+ ModelAPI_FeatureUpdatedMessage aMsg(aThis, aFeature, anEvent);
+ Event_Loop::loop()->send(aMsg);
+
+ if (aFIter == aFeatures.end()) {
+ aFeatures.push_back(aFeature);
+ aFIter = aFeatures.end();
+ } else {
+ aFIter++;
+ aFeatures.insert(aFIter, aFeature);
+ }
+ // feature for this label is added, so go to the next label
+ aFLabIter.Next();
+ } else { // nothing is changed, both iterators are incremented
+ aFIter++;
+ aFLabIter.Next();
+ }
+ }
+ }
+ }
--- /dev/null
- const std::shared_ptr<ModelAPI_Document>& theDoc,
- const std::shared_ptr<ModelAPI_Feature>& theFeature, const Event_ID& theEvent)
+ // File: Model_Events.cxx
+ // Created: 10 Apr 2014
+ // Author: Mikhail PONIKAROV
+
+ #include <Model_Events.h>
+ #include <Event_Loop.h>
+
+ ModelAPI_FeatureUpdatedMessage::ModelAPI_FeatureUpdatedMessage(
- const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
++ const boost::shared_ptr<ModelAPI_Document>& theDoc,
++ const boost::shared_ptr<ModelAPI_Feature>& theFeature, const Event_ID& theEvent)
+ : Event_Message(theEvent, 0), myFeature(theFeature), myDoc(theDoc)
+ {}
+
+ ModelAPI_FeatureDeletedMessage::ModelAPI_FeatureDeletedMessage(
++ const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
+ : Event_Message(messageId(), 0), myDoc(theDoc), myGroup(theGroup)
+
+ {
+ }
+
+ const Event_ID ModelAPI_FeatureDeletedMessage::messageId()
+ {
+ static Event_ID MY_ID = Event_Loop::eventByName(EVENT_FEATURE_DELETED);
+ return MY_ID;
+ }
--- /dev/null
-shared_ptr<ModelAPI_Feature> Model_Iterator::current()
+ // File: Model_Iterator.hxx
+ // Created: 1 Apr 2014
+ // Author: Mikhail PONIKAROV
+
+ #include "Model_Iterator.h"
+ #include "Model_Document.h"
+ #include "ModelAPI_Feature.h"
+ #include "Model_Data.h"
+ #include <TDataStd_Comment.hxx>
+ #include <TDataStd_Name.hxx>
+
+ using namespace std;
+
+ void Model_Iterator::next()
+ {
+ return myIter.Next();
+ }
+
+ bool Model_Iterator::more()
+ {
+ return myIter.More() == Standard_True;
+ }
+
-bool Model_Iterator::isEqual(std::shared_ptr<ModelAPI_Feature> theFeature)
++boost::shared_ptr<ModelAPI_Feature> Model_Iterator::current()
+ {
+ TDF_Label aLab = myIter.Value()->Label();
+ return myDoc->feature(aLab);
+ }
+
+ string Model_Iterator::currentKind()
+ {
+ return string(TCollection_AsciiString(
+ Handle(TDataStd_Comment)::DownCast(myIter.Value())->Get()).ToCString());
+ }
+
+ string Model_Iterator::currentName()
+ {
+ TDF_Label aLab = myIter.Value()->Label();
+ Handle(TDataStd_Name) aName;
+ if (aLab.FindAttribute(TDataStd_Name::GetID(), aName))
+ return string(TCollection_AsciiString(aName->Get()).ToCString());
+ return ""; // name is not found
+ }
+
+ int Model_Iterator::numIterationsLeft()
+ {
+ int aResult = 0;
+ TDF_ChildIDIterator aTempIter(myIter);
+ for(; aTempIter.More(); aTempIter.Next())
+ aResult++;
+ return aResult;
+ }
+
- dynamic_pointer_cast<Model_Data>(theFeature->data())->label()) == Standard_True;
++bool Model_Iterator::isEqual(boost::shared_ptr<ModelAPI_Feature> theFeature)
+ {
+ return (myIter.Value()->Label() ==
-Model_Iterator::Model_Iterator(std::shared_ptr<Model_Document> theDoc, TDF_Label theLab)
++ boost::dynamic_pointer_cast<Model_Data>(theFeature->data())->label()) == Standard_True;
+
+ }
+
+ Model_Iterator::Model_Iterator()
+ {
+ }
+
++Model_Iterator::Model_Iterator(boost::shared_ptr<Model_Document> theDoc, TDF_Label theLab)
+ : myDoc(theDoc), myIter(theLab, TDataStd_Comment::GetID(), Standard_False)
+ {}
--- /dev/null
-shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
+ // File: Model_PluginManager.cxx
+ // Created: 20 Mar 2014
+ // Author: Mikhail PONIKAROV
+
+ #include <Model_PluginManager.h>
+ #include <ModelAPI_Feature.h>
+ #include <ModelAPI_Plugin.h>
+ #include <Model_Data.h>
+ #include <Model_Document.h>
+ #include <Model_Application.h>
+ #include <Event_Loop.h>
+ #include <Config_FeatureMessage.h>
+ #include <Config_ModuleReader.h>
+
+ using namespace std;
+
+ static Model_PluginManager* myImpl = new Model_PluginManager();
+
- std::shared_ptr<ModelAPI_Feature> aCreated =
++boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
+ {
+ if (this != myImpl) return myImpl->createFeature(theFeatureID);
+
+ LoadPluginsInfo();
+ if (myPlugins.find(theFeatureID) != myPlugins.end()) {
+ myCurrentPluginName = myPlugins[theFeatureID];
+ if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
+ // load plugin library if not yet done
+ loadLibrary(myCurrentPluginName);
+ }
+ if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
- return std::shared_ptr<ModelAPI_Feature>(); // return nothing
++ boost::shared_ptr<ModelAPI_Feature> aCreated =
+ myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
+ return aCreated;
+ }
+ }
+
-std::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
++ return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
+ }
+
- return std::shared_ptr<ModelAPI_Document>(
++boost::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
+ {
-shared_ptr<ModelAPI_Document> Model_PluginManager::currentDocument()
++ return boost::shared_ptr<ModelAPI_Document>(
+ Model_Application::getApplication()->getDocument("root"));
+ }
+
+ bool Model_PluginManager::hasRootDocument()
+ {
+ return Model_Application::getApplication()->hasDocument("root");
+ }
+
-void Model_PluginManager::setCurrentDocument(shared_ptr<ModelAPI_Document> theDoc)
++boost::shared_ptr<ModelAPI_Document> Model_PluginManager::currentDocument()
+ {
+ if (!myCurrentDoc)
+ myCurrentDoc = rootDocument();
+ return myCurrentDoc;
+ }
+
- ModelAPI_PluginManager::SetPluginManager(std::shared_ptr<ModelAPI_PluginManager>(this));
++void Model_PluginManager::setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc)
+ {
+ myCurrentDoc = theDoc;
+ }
+
+ Model_PluginManager::Model_PluginManager()
+ {
+ myPluginsInfoLoaded = false;
+ //TODO(sbh): Implement static method to extract event id [SEID]
+ static Event_ID aFeatureEvent = Event_Loop::eventByName("FeatureRegisterEvent");
+
++ ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
+ // register the configuration reading listener
+ Event_Loop* aLoop = Event_Loop::loop();
+ aLoop->registerListener(this, aFeatureEvent);
+ }
+
+ void Model_PluginManager::processEvent(const Event_Message* theMessage)
+ {
+ const Config_FeatureMessage* aMsg =
+ dynamic_cast<const Config_FeatureMessage*>(theMessage);
+ if (aMsg) {
+ // proccess the plugin info, load plugin
+ if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
+ myPlugins[aMsg->id()] = aMsg->pluginLibrary();
+ }
+ }
+ // plugins information was started to load, so, it will be loaded
+ myPluginsInfoLoaded = true;
+ }
+
+ void Model_PluginManager::LoadPluginsInfo()
+ {
+ if (myPluginsInfoLoaded) // nothing to do
+ return;
+
+ // Read plugins information from XML files
+ Config_ModuleReader aXMLReader("FeatureRegisterEvent");
+ aXMLReader.setAutoImport(true);
+ aXMLReader.readAll();
+ }
+
+ void Model_PluginManager::registerPlugin(ModelAPI_Plugin* thePlugin)
+ {
+ myPluginObjs[myCurrentPluginName] = thePlugin;
+ }
--- /dev/null
-std::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
+ // File: ModelAPI_PluginManager.hxx
+ // Created: 20 Mar 2014
+ // Author: Mikhail PONIKAROV
+
+ #include <ModelAPI_PluginManager.h>
+ // to avoid unresolved ModelAPI_Document()
+ #include <ModelAPI_Document.h>
+ // to avoid unresolved ModelAPI_Feature()
+ #include <ModelAPI_Feature.h>
+ // to avoid unresolved ModelAPI_Data()
+ #include <ModelAPI_Data.h>
+ // to avoid unresolved ModelAPI_Plugin()
+ #include <ModelAPI_Plugin.h>
+ // to avoid unresolved ModelAPI_Iterator()
+ #include <ModelAPI_Iterator.h>
+ // to avoid unresolved ModelAPI_Iterator()
+ #include <ModelAPI_Iterator.h>
+ #include <ModelAPI_Attribute.h>
+ #include <ModelAPI_AttributeDocRef.h>
+ #include <ModelAPI_AttributeDouble.h>
+
+ #ifdef WIN32
+ #include <windows.h>
+ #else
+ #include <dlfcn.h>
+ #endif
+
+ using namespace std;
+
+ /// Converts library name to the operation system file name
+ string library(const string& theLibName);
+
+ /// Manager that will be initialized from Model package, one per application
- std::shared_ptr<ModelAPI_PluginManager> theManager)
++boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
+
+ ModelAPI_PluginManager::ModelAPI_PluginManager()
+ {
+ }
+
+ void ModelAPI_PluginManager::SetPluginManager(
-std::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
++ boost::shared_ptr<ModelAPI_PluginManager> theManager)
+ {
+ MY_MANAGER = theManager;
+ }
+
++boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
+ {
+ if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
+ loadLibrary("Model");
+ }
+ return MY_MANAGER;
+ }
+
+ string library(const string& theLibName)
+ {
+ string aLibName = theLibName;
+
+ #ifndef WIN32
+ static string aLibExt( ".so" );
+ if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
+ aLibName = "lib" + aLibName;
+ #else
+ static string aLibExt( ".dll" );
+ #endif
+
+ string anExt = aLibName.substr(aLibName.size() - 4);
+
+ if ( anExt != aLibExt)
+ aLibName += aLibExt;
+
+ return aLibName;
+ }
+
+ // for debug purpose only (cerr), before the error management system is implemented
+ #include <iostream>
+ void ModelAPI_PluginManager::loadLibrary(const string theLibName)
+ {
+ string aFileName = library(theLibName);
+ if ( aFileName.empty() )
+ {
+ cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
+ return;
+ }
+
+ #ifdef WIN32
+ HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
+ if (!aModLib)
+ cerr<<"Failed to load "<<aFileName.c_str()<<endl;
+ #else
+ void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
+ if ( !aModLib )
+ cerr<<"Failed to load "<<aFileName.c_str()<<endl;
+ #endif
+ }
//!< Next fields could be extracted into a subclass;
QString myOperationId;
- QString myXmlRepr;
- std::shared_ptr<ModelAPI_Feature> myFeature;
+ boost::shared_ptr<ModelAPI_Feature> myFeature;
};
#endif
*/
const TopoDS_Shape& PartSet_OperationSketchBase::preview() const
{
- shared_ptr<SketchPlugin_Feature> aFeature = dynamic_pointer_cast<SketchPlugin_Feature>(feature());
+ boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
- return aFeature->preview();
+ return *(static_cast<TopoDS_Shape*>(aFeature->preview()->implementation()));
}
/*!
--- /dev/null
- shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PART_ATTR_DOC_REF);
+ // File: PartSetPlugin_Part.cxx
+ // Created: 27 Mar 2014
+ // Author: Mikhail PONIKAROV
+
+ #include "PartSetPlugin_Part.h"
+ #include "ModelAPI_PluginManager.h"
+ #include "ModelAPI_Document.h"
+ #include "ModelAPI_Data.h"
+ #include "ModelAPI_Iterator.h"
+ #include "ModelAPI_AttributeDocRef.h"
+
+ using namespace std;
+
+ PartSetPlugin_Part::PartSetPlugin_Part()
+ {
+ }
+
+ void PartSetPlugin_Part::initAttributes()
+ {
+ data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type());
+ }
+
+ void PartSetPlugin_Part::execute()
+ {
- shared_ptr<ModelAPI_Document> aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument();
++ boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PART_ATTR_DOC_REF);
+ if (!aDocRef->value()) { // create a document if not yet created
-shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd() {
++ boost::shared_ptr<ModelAPI_Document> aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument();
+ aDocRef->setValue(aPartSetDoc->subDocument(data()->getName()));
+ }
+ }
+
++boost::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd() {
+ return ModelAPI_PluginManager::get()->rootDocument();
+ }
--- /dev/null
-shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
+ #include "PartSetPlugin_Plugin.h"
+ #include "PartSetPlugin_Part.h"
+ #include <ModelAPI_PluginManager.h>
+ #include <ModelAPI_Document.h>
+
+ using namespace std;
+
+ // the only created instance of this plugin
+ static PartSetPlugin_Plugin* MY_INSTANCE = new PartSetPlugin_Plugin();
+
+ PartSetPlugin_Plugin::PartSetPlugin_Plugin()
+ {
+ // register this plugin
+ ModelAPI_PluginManager::get()->registerPlugin(this);
+ }
+
- return shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Part);
++boost::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
+ {
+ if (theFeatureID == "Part") {
- return shared_ptr<ModelAPI_Feature>();
++ return boost::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Part);
+ }
+ // feature of such kind is not found
++ return boost::shared_ptr<ModelAPI_Feature>();
+ }
/**
* Returns the sketch preview
*/
- const TopoDS_Shape& SketchPlugin_Feature::preview()
-const std::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::preview()
++const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::preview()
{
return myPreview;
}
* Set the shape to the internal preview field
* \param theShape a preview shape
*/
- void SketchPlugin_Feature::setPreview(const TopoDS_Shape& theShape)
-void SketchPlugin_Feature::setPreview(const std::shared_ptr<GeomAPI_Shape>& theShape)
++void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
{
myPreview = theShape;
}
class SketchPlugin_Feature: public ModelAPI_Feature
{
public:
- SKETCHPLUGIN_EXPORT virtual const TopoDS_Shape& preview() = 0;
- SKETCHPLUGIN_EXPORT virtual const std::shared_ptr<GeomAPI_Shape>& preview() = 0;
++ SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
protected:
- void setPreview(const TopoDS_Shape& theShape); ///< the preview shape
- void setPreview(const std::shared_ptr<GeomAPI_Shape>& theShape); ///< the preview shape
++ void setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape); ///< the preview shape
private:
- TopoDS_Shape myPreview; ///< the preview shape
- std::shared_ptr<GeomAPI_Shape> myPreview; ///< the preview shape
++ boost::shared_ptr<GeomAPI_Shape> myPreview; ///< the preview shape
};
#endif
void SketchPlugin_Sketch::execute()
{
- /*shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PART_ATTR_DOC_REF);
- if (!aDocRef->value()) { // create a document if not yet created
- shared_ptr<ModelAPI_Document> aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument();
- aDocRef->setValue(aPartSetDoc->subDocument(data()->getName()));
- }*/
}
- const TopoDS_Shape& SketchPlugin_Sketch::preview()
-const shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
++const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
{
- if (SketchPlugin_Feature::preview().IsNull())
+ if (!SketchPlugin_Feature::preview())
{
- gp_Pnt anOrigin(0, 0, 0);
- gp_Dir aDir(gp_Vec(gp_Pnt(0,0,0), gp_Pnt(1,0,0)));
- gp_Pln aPlane(anOrigin, aDir);
- BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, PLANE_U_MIN, PLANE_U_MAX, PLANE_V_MIN,
- PLANE_V_MAX);
- setPreview(aFaceBuilder.Face());
+
- shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
- shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(1, 0, 0));
- shared_ptr<GeomAPI_Shape> aFace =
++ boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
++ boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(1, 0, 0));
++ boost::shared_ptr<GeomAPI_Shape> aFace =
+ GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
+ setPreview(aFace);
}
return SketchPlugin_Feature::preview();
}
SKETCHPLUGIN_EXPORT virtual void initAttributes();
/// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const TopoDS_Shape& preview();
- SKETCHPLUGIN_EXPORT virtual const std::shared_ptr<GeomAPI_Shape>& preview();
++ SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
/// Use plugin manager for features creation
SketchPlugin_Sketch();
aContext->UpdateCurrentViewer();
}
-void XGUI_Displayer::Erase(std::shared_ptr<ModelAPI_Feature> theFeature,
+
+ /*!
+ * Erase the feature and a shape.
+ * \param theFeature a feature instance
+ * \param theFeature a shape
+ */
++void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape)
+ {
+ Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
+ aContext->EraseAll();
+ }
XGUI_Displayer(XGUI_Viewer* theViewer);
virtual ~XGUI_Displayer();
- void Display(std::shared_ptr<ModelAPI_Feature> theFeature);
+ void Display(boost::shared_ptr<ModelAPI_Feature> theFeature);
- void Display(std::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
+ void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
- void Erase(std::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
++ void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
+
protected:
XGUI_Viewer* myViewer; ///< the viewer
};