Model_Document.h
Model_PluginManager.h
Model_Data.h
- Model_Object.h
Model_AttributeDouble.h
Model_AttributeDocRef.h
Model_AttributeReference.h
Model_Events.h
Model_Update.h
Model_Validator.h
+ Model_ResultBody.h
+ Model_ResultConstruction.h
+ Model_ResultPart.h
)
SET(PROJECT_SOURCES
Model_Document.cpp
Model_PluginManager.cpp
Model_Data.cpp
- Model_Object.cpp
Model_AttributeDouble.cpp
Model_AttributeDocRef.cpp
Model_AttributeReference.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
+ Model_ResultBody.cpp
+ Model_ResultConstruction.cpp
+ Model_ResultPart.cpp
)
SET(PROJECT_LIBRARIES
#include <TDataStd_Name.hxx>
#include "Model_Events.h"
#include <Events_Loop.h>
+#include <Events_Error.h>
using namespace std;
myLab = theLab;
}
-string Model_Data::getName()
+string Model_Data::name()
{
Handle(TDataStd_Name) aName;
if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
aName->Set(theName.c_str());
}
if (isModified) {
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent, false);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
}
}
if (anAttr) {
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
- anAttr->setFeature(myFeature);
+ anAttr->setObject(myObject);
+ }
+ else {
+ Events_Error::send("Can not create unknown type of attribute " + theAttrType);
}
- else
- ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
}
boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
{
theAttr->setInitialized();
- static const Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
-}
-
-#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>();
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
}
/// All attributes of the object identified by the attribute ID
std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> > myAttrs;
- /// needed here to emit signal that feature changed on change of the attribute
- FeaturePtr myFeature;
+ /// needed here to emit signal that object changed on change of the attribute
+ ObjectPtr myObject;
Model_Data();
public:
/// Returns the name of the feature visible by the user in the object browser
- MODEL_EXPORT virtual std::string getName();
+ MODEL_EXPORT virtual std::string name();
/// Defines the name of the feature visible by the user in the object browser
MODEL_EXPORT virtual void setName(std::string theName);
/// Returns the attribute that references to another document
/// 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();
+ /// Returns the label where the shape must be stored (used in ResultBody)
+ TDF_Label& shapeLab() {return myLab;}
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
/// Puts feature to the document data sub-structure
MODEL_EXPORT void setLabel(TDF_Label& theLab);
- /// Sets the feature of this data
- MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature)
- {myFeature = theFeature;}
+ /// Sets the object of this data
+ MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
+ {myObject = theObject;}
};
#endif
// Author: Mikhail PONIKAROV
#include <Model_Document.h>
-#include <ModelAPI_Feature.h>
#include <Model_Data.h>
-#include <Model_Object.h>
#include <Model_Application.h>
#include <Model_PluginManager.h>
#include <Model_Events.h>
+#include <Model_ResultPart.h>
+#include <Model_ResultConstruction.h>
+#include <Model_ResultBody.h>
#include <Events_Loop.h>
#include <Events_Error.h>
#include <TDataStd_ReferenceArray.hxx>
#include <TDataStd_HLabelArray1.hxx>
#include <TDataStd_Name.hxx>
+#include <TDF_Reference.hxx>
#include <climits>
#ifndef WIN32
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 (features)
+static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (features, results)
static const int TAG_HISTORY = 3; // tag of the history sub-tree (python dump)
+// feature sub-labels
+static const int TAG_FEATURE_ARGUMENTS = 1; ///< where the arguments are located
+static const int TAG_FEATURE_RESULTS = 2; ///< where the results are located
+
using namespace std;
/// Returns the file name of this document by the nameof directory and identifuer of a document
void Model_Document::finishOperation()
{
// just to be sure that everybody knows that changes were performed
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
if (myNestedNum != -1) // this nested transaction is owervritten
myNestedNum++;
subDocument(*aSubIter)->redo();
}
-FeaturePtr Model_Document::addFeature(string theID)
-{
- FeaturePtr aFeature =
- ModelAPI_PluginManager::get()->createFeature(theID);
- if (aFeature) {
- boost::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd())->addFeature(aFeature);
- } else {
- // TODO: generate error that feature is not created
- }
- return aFeature;
-}
-
/// Appenad to the array of references a new referenced label
static void AddToRefArray(TDF_Label& theArrayLab, TDF_Label& theReferenced) {
Handle(TDataStd_ReferenceArray) aRefs;
}
}
-void Model_Document::addFeature(const FeaturePtr theFeature)
-{
- if (theFeature->isAction()) return; // do not add action to the data model
-
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- TDF_Label aFeaturesLab = groupLabel(FEATURES_GROUP);
- TDF_Label aFeatureLab = aFeaturesLab.NewChild();
- // organize feature and data objects
- boost::shared_ptr<Model_Data> aData(new Model_Data);
- aData->setFeature(theFeature);
- aData->setLabel(aFeatureLab);
- theFeature->setDoc(aThis);
- theFeature->setData(aData);
- setUniqueName(theFeature);
- theFeature->initAttributes();
-
- // keep the feature ID to restore document later correctly
- TDataStd_Comment::Set(aFeatureLab, theFeature->getKind().c_str());
- myFeatures.push_back(theFeature);
- // store feature in the history of features array
- if (theFeature->isInHistory()) {
- AddToRefArray(aFeaturesLab, aFeatureLab);
+FeaturePtr Model_Document::addFeature(string theID)
+{
+ TDF_Label anEmptyLab;
+ FeaturePtr anEmptyFeature;
+ FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
+ if (aFeature) {
+ TDF_Label aFeatureLab;
+ if (!aFeature->isAction()) {// do not add action to the data model
+ TDF_Label aFeaturesLab = groupLabel(FEATURES_GROUP);
+ aFeatureLab = aFeaturesLab.NewChild();
+ initData(aFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS);
+ // keep the feature ID to restore document later correctly
+ TDataStd_Comment::Set(aFeatureLab, aFeature->getKind().c_str());
+ myObjs[FEATURES_GROUP].push_back(aFeature);
+ // store feature in the history of features array
+ if (aFeature->isInHistory()) {
+ AddToRefArray(aFeaturesLab, aFeatureLab);
+ }
+ }
+ setUniqueName(aFeature);
+ if (!aFeature->isAction()) {// do not add action to the data model
+ // event: feature is added
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
+ }
}
- // add featue to the group
- const std::string& aGroup = theFeature->getGroup();
- TDF_Label aGroupLab = groupLabel(aGroup);
- AddToRefArray(aGroupLab, aFeatureLab);
- // new name of this feature object by default equal to name of feature
- TDF_Label anObjLab = aGroupLab.NewChild();
- TCollection_ExtendedString aName(theFeature->data()->getName().c_str());
- TDataStd_Name::Set(anObjLab, aName);
- TDF_Label aGrLabChild = aGroupLab.FindChild(1);
- AddToRefArray(aGrLabChild, anObjLab); // reference to names is on the first sub
-
- // event: feature is added
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(theFeature, anEvent);
+ return aFeature;
+}
+
+void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Result> theResult,
+ const int theResultIndex)
+{
+ initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theResult->owner()->data())->
+ label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex);
}
/// Appenad to the array of references a new referenced label.
void Model_Document::removeFeature(FeaturePtr theFeature)
{
boost::shared_ptr<Model_Data> aData = boost::static_pointer_cast<Model_Data>(theFeature->data());
- TDF_Label aFeatureLabel = aData->label();
- // remove the object
- TDF_Label aGroupLabel = groupLabel(theFeature->getGroup());
- int aRemovedIndex = RemoveFromRefArray(aGroupLabel, aFeatureLabel);
- RemoveFromRefArray(aGroupLabel.FindChild(1), TDF_Label(), aRemovedIndex);
- // remove feature from the myFeatures list
- std::vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
- while(aFIter != myFeatures.end()) {
- if (*aFIter == theFeature) {
- aFIter = myFeatures.erase(aFIter);
+ TDF_Label aFeatureLabel = aData->label().Father();
+ // remove feature from the myObjects list
+ std::vector<ObjectPtr>& aVec = myObjs[FEATURES_GROUP];
+ std::vector<ObjectPtr>::iterator anIter = aVec.begin();
+ while(anIter != aVec.end()) {
+ if (*anIter == theFeature) {
+ anIter = aVec.erase(anIter);
} else {
- aFIter++;
+ anIter++;
}
}
// erase all attributes under the label of feature
// remove it from the references array
RemoveFromRefArray(groupLabel(FEATURES_GROUP), aData->label());
- // event: feature is added
- ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), theFeature->getGroup());
+ // event: feature is deleted
+ ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), FEATURES_GROUP);
+}
+
+/// returns the object group name by the object label
+static string groupName(TDF_Label theObjectLabel) {
+ TDF_Label aGroupLab = theObjectLabel.Father();
+ Handle(TDataStd_Comment) aComment;
+ if (aGroupLab.FindAttribute(TDataStd_Comment::GetID(), aComment))
+ return string(TCollection_AsciiString(aComment->Get()).ToCString());
+ return ""; // not found
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel)
{
// iterate all features, may be optimized later by keeping labels-map
- vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
- for(; aFIter != myFeatures.end(); aFIter++) {
+ std::vector<ObjectPtr>& aVec = myObjs[FEATURES_GROUP];
+ vector<ObjectPtr>::iterator aFIter = aVec.begin();
+ for(; aFIter != aVec.end(); aFIter++) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
if (aData->label().IsEqual(theLabel))
- return *aFIter;
+ return boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter);
}
return FeaturePtr(); // not found
}
return Model_Application::getApplication()->getDocument(theDocID);
}
-FeaturePtr Model_Document::feature(
- const string& theGroupID, const int theIndex, const bool isOperation)
+ObjectPtr Model_Document::object(const string& theGroupID, const int theIndex)
{
- TDF_Label aGroupLab = groupLabel(theGroupID);
- Handle(TDataStd_ReferenceArray) aRefs;
- if (aGroupLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
- if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) {
- TDF_Label aFeatureLab = aRefs->Value(theIndex);
- FeaturePtr aFeature = feature(aFeatureLab);
-
- if (theGroupID == FEATURES_GROUP || isOperation) { // just returns the feature from the history
- return aFeature;
- } else { // create a new object from the group to return it
- Handle(TDataStd_Name) aName; // name of the object
- if (aGroupLab.FindChild(1).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
- aRefs->Value(theIndex).FindAttribute(TDataStd_Name::GetID(), aName);
- boost::shared_ptr<Model_Object> anObj(new Model_Object(aFeature, aName));
- return anObj;
+ if (theGroupID == FEATURES_GROUP) {
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind = myObjs.find(theGroupID);
+ if (aFind != myObjs.end()) {
+ int aSize = aFind->second.size();
+ if (theIndex >= 0 && theIndex < aSize)
+ return aFind->second[theIndex];
+ }
+ } else {
+ // iterate all features in order to find the needed result
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind = myObjs.find(FEATURES_GROUP);
+ if (aFind != myObjs.end()) {
+ vector<ObjectPtr>::iterator aFIter = aFind->second.begin();
+ for(int anIndex = 0; aFIter != aFind->second.end(); aFIter++) {
+ const list<boost::shared_ptr<ModelAPI_Result> >& aResults =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter)->results();
+ list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for(; aRIter != aResults.cend(); aRIter++) {
+ if ((*aRIter)->isInHistory() && (*aRIter)->group() == theGroupID) {
+ if (anIndex == theIndex)
+ return *aRIter;
+ anIndex++;
+ }
+ }
}
}
}
-
// not found
- return FeaturePtr();
+ return ObjectPtr();
}
int Model_Document::size(const string& theGroupID)
{
- Handle(TDataStd_ReferenceArray) aRefs;
- if (groupLabel(theGroupID).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
- return aRefs->Length();
+ int aResult = 0;
+ if (theGroupID == FEATURES_GROUP) {
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind = myObjs.find(theGroupID);
+ if (aFind != myObjs.end()) {
+ aResult = aFind->second.size();
+ }
+ } else {
+ // iterate all features in order to find the needed result
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind = myObjs.find(FEATURES_GROUP);
+ if (aFind != myObjs.end()) {
+ vector<ObjectPtr>::iterator aFIter = aFind->second.begin();
+ for(; aFIter != aFind->second.end(); aFIter++) {
+ const list<boost::shared_ptr<ModelAPI_Result> >& aResults =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter)->results();
+ list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for(; aRIter != aResults.cend(); aRIter++) {
+ if ((*aRIter)->isInHistory() && (*aRIter)->group() == theGroupID) {
+ aResult++;
+ }
+ }
+ }
+ }
+ }
// group is not found
- return 0;
+ return aResult;
}
Model_Document::Model_Document(const std::string theID)
void Model_Document::setUniqueName(FeaturePtr theFeature)
{
string aName; // result
- // iterate all features but also iterate group of this feature if object is not in history
- list<string> aGroups;
- aGroups.push_back(FEATURES_GROUP);
- if (!theFeature->isInHistory()) {
- aGroups.push_back(theFeature->getGroup());
+ // first count all objects of such kind to start with index = count + 1
+ int a, aNumObjects = 0;
+ int aSize = size(FEATURES_GROUP);
+ for(a = 0; a < aSize; a++) {
+ if (boost::dynamic_pointer_cast<ModelAPI_Feature>(object(FEATURES_GROUP, a))->getKind()
+ == theFeature->getKind())
+ aNumObjects++;
}
- for(list<string>::iterator aGIter = aGroups.begin(); aGIter != aGroups.end(); aGIter++) {
- // first count all objects of such kind to start with index = count + 1
- int a, aNumObjects = 0;
- int aSize = size(*aGIter);
- for(a = 0; a < aSize; a++) {
- if (feature(*aGIter, a)->getKind() == theFeature->getKind())
- aNumObjects++;
- }
- // generate candidate name
- stringstream aNameStream;
- aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
- aName = aNameStream.str();
- // check this is unique, if not, increase index by 1
- for(a = 0; a < aSize;) {
- if (feature(*aGIter, a, true)->data()->getName() == aName) {
- aNumObjects++;
- stringstream aNameStream;
- aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
- aName = aNameStream.str();
- // reinitialize iterator to make sure a new name is unique
- a = 0;
- } else a++;
- }
+ // generate candidate name
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ aName = aNameStream.str();
+ // check this is unique, if not, increase index by 1
+ for(a = 0; a < aSize;) {
+ if (boost::dynamic_pointer_cast<ModelAPI_Feature>(object(FEATURES_GROUP, a))
+ ->data()->name() == aName) {
+ aNumObjects++;
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ aName = aNameStream.str();
+ // reinitialize iterator to make sure a new name is unique
+ a = 0;
+ } else a++;
}
theFeature->data()->setName(aName);
}
-//! Returns the object by the feature
-FeaturePtr Model_Document::objectByFeature(
- const FeaturePtr theFeature)
-{
- for(int a = 0; a < size(theFeature->getGroup()); a++) {
- boost::shared_ptr<Model_Object> anObj =
- boost::dynamic_pointer_cast<Model_Object>(feature(theFeature->getGroup(), a));
- if (anObj && anObj->featureRef() == theFeature) {
- return anObj;
- }
- }
- return FeaturePtr(); // not found
+void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag) {
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ boost::shared_ptr<Model_Data> aData(new Model_Data);
+ aData->setLabel(theLab.FindChild(theTag));
+ aData->setObject(theObj);
+ theObj->setDoc(aThis);
+ theObj->setData(aData);
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
+ if (aFeature) aFeature->initAttributes();
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
{
- boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
- // update features
- vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
- // and in parallel iterate labels of features
- TDF_ChildIDIterator aFLabIter(groupLabel(FEATURES_GROUP), TDataStd_Comment::GetID());
- while(aFIter != myFeatures.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 != myFeatures.end()) { // existing tag for feature
- 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
- FeaturePtr aFeature = *aFIter;
- aFIter = myFeatures.erase(aFIter);
- // event: model is updated
- if (aFeature->isInHistory()) {
- ModelAPI_EventCreator::get()->sendDeleted(aThis, FEATURES_GROUP);
- }
- ModelAPI_EventCreator::get()->sendDeleted(aThis, aFeature->getGroup());
- } else if (aDSTag < aFeatureTag) { // a new feature is inserted
- // create a feature
- FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(
- TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
- aFLabIter.Value())->Get()).ToCString());
-
- if (aFIter == myFeatures.end()) { // must be before "setData" to redo the sketch line correctly
- myFeatures.push_back(aFeature);
- aFIter = myFeatures.end();
- } else {
- aFIter++;
- myFeatures.insert(aFIter, aFeature);
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ // update all objects: iterate from the end: as they appeared in the list
+ map<string, vector<ObjectPtr> >::reverse_iterator aGroupIter = myObjs.rbegin();
+ for(; aGroupIter != myObjs.rend(); aGroupIter++) {
+ vector<ObjectPtr>::iterator anObjIter = aGroupIter->second.begin();
+ // and in parallel iterate labels of features
+ const string& aGroupName = aGroupIter->first;
+ TDF_ChildIDIterator aLabIter(groupLabel(aGroupName), TDataStd_Comment::GetID());
+ while(anObjIter != aGroupIter->second.end() || aLabIter.More()) {
+ static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
+ int aFeatureTag = INFINITE_TAG;
+ if (anObjIter != aGroupIter->second.end()) { // existing tag for feature
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>((*anObjIter)->data());
+ aFeatureTag = aData->label().Tag();
}
- boost::shared_ptr<Model_Data> aData(new Model_Data);
- TDF_Label aLab = aFLabIter.Value()->Label();
- aData->setLabel(aLab);
- aData->setFeature(aFeature);
- aFeature->setDoc(aThis);
- aFeature->setData(aData);
- aFeature->initAttributes();
-
- // event: model is updated
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
- FeaturePtr anObj = objectByFeature(aFeature);
- if (anObj) {
- ModelAPI_EventCreator::get()->sendUpdated(anObj, anEvent);
+ int aDSTag = INFINITE_TAG;
+ if (aLabIter.More()) { // next label in DS is existing
+ aDSTag = aLabIter.Value()->Label().Tag();
}
-
- // feature for this label is added, so go to the next label
- aFLabIter.Next();
- } else { // nothing is changed, both iterators are incremented
- if (theMarkUpdated) {
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(*aFIter, anEvent);
+ if (aDSTag > aFeatureTag) { // feature is removed
+ ObjectPtr anObj = *anObjIter;
+ anObjIter = aGroupIter->second.erase(anObjIter);
+ // event: model is updated
+ if (anObj->isInHistory()) {
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, aGroupName);
+ }
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, aGroupName);
+ } else if (aDSTag < aFeatureTag) { // a new feature is inserted
+ // create a feature
+ TDF_Label aLab = aLabIter.Value()->Label();
+ ObjectPtr aNewObj = ModelAPI_PluginManager::get()->createFeature(
+ TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
+ .ToCString());
+ // this must be before "setData" to redo the sketch line correctly
+ if (anObjIter == aGroupIter->second.end()) {
+ aGroupIter->second.push_back(aNewObj);
+ anObjIter = aGroupIter->second.end();
+ } else {
+ anObjIter++;
+ aGroupIter->second.insert(anObjIter, aNewObj);
+ }
+ initData(aNewObj, aLab, TAG_FEATURE_ARGUMENTS);
+
+ // event: model is updated
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent);
+ // feature for this label is added, so go to the next label
+ aLabIter.Next();
+ } else { // nothing is changed, both iterators are incremented
+ if (theMarkUpdated) {
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(*anObjIter, anEvent);
+ }
+ anObjIter++;
+ aLabIter.Next();
}
- aFIter++;
- aFLabIter.Next();
}
}
// after all updates, sends a message that groups of features were created or updated
boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
setCheckTransactions(false);
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
if (theMarkUpdated)
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
setCheckTransactions(true);
}
+
+boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction()
+{
+ boost::shared_ptr<ModelAPI_ResultConstruction> aResult(new Model_ResultConstruction());
+ return aResult;
+}
#include <Model.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <TDocStd_Document.hxx>
#include <map>
//! \param creates feature and puts it in the document
MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID);
- //! Removes the feature from the document
+ //! Removes the feature from the document (with result)
MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
//! Returns the existing feature by the label
//! \param theGroupID group that contains a feature
//! \param theIndex zero-based index of feature in the group
//! \param isOperation if it is true, returns feature (not Object)
- MODEL_EXPORT virtual FeaturePtr
- feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false);
+ MODEL_EXPORT virtual ObjectPtr object(const std::string& theGroupID, const int theIndex);
//! Returns the number of features in the group
MODEL_EXPORT virtual int size(const std::string& theGroupID);
+ //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
+ MODEL_EXPORT virtual void storeResult(
+ boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex);
+
+ /// Creates a construction cresults
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction();
+
protected:
//! Returns (creates if needed) the group label
//! feature type + "_" + index
void setUniqueName(FeaturePtr theFeature);
- //! Adds to the document the new feature
- void addFeature(const FeaturePtr theFeature);
-
- //! Returns the object by the feature
- FeaturePtr objectByFeature(
- const FeaturePtr theFeature);
-
//! Synchronizes myFeatures list with the updated document
void synchronizeFeatures(const bool theMarkUpdated = false);
//! performas compactification of all nested operations into one
void compactNested();
+ //! Initializes the data fields of the feature
+ void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag);
+
+
+
friend class Model_Application;
friend class Model_PluginManager;
friend class DFBrowser;
int myTransactionsAfterSave;
/// number of nested transactions performed (or -1 if not nested)
int myNestedNum;
- /// All features managed by this document (not only in history of OB)
- std::vector<FeaturePtr > myFeatures;
+ /// All objects managed by this document (not only in history of OB)
+ std::map<std::string, std::vector<ObjectPtr> > myObjs;
///< set of identifiers of sub-documents of this document
std::set<std::string> mySubs;
/////////////////////// CREATOR /////////////////////////////
void Model_EventCreator::sendUpdated(
- const FeaturePtr& theFeature, const Events_ID& theEvent, const bool isGroupped) const
+ const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped) const
{
- Model_FeatureUpdatedMessage aMsg(theFeature, theEvent);
+ Model_ObjectUpdatedMessage aMsg(theObject, theEvent);
Events_Loop::loop()->send(aMsg, isGroupped);
}
void Model_EventCreator::sendDeleted(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const
{
- Model_FeatureDeletedMessage aMsg(theDoc, theGroup);
+ Model_ObjectDeletedMessage aMsg(theDoc, theGroup);
Events_Loop::loop()->send(aMsg, true);
}
}
/////////////////////// UPDATED MESSAGE /////////////////////////////
-Model_FeatureUpdatedMessage::Model_FeatureUpdatedMessage(
- const FeaturePtr& theFeature,
- const Events_ID& theEvent) : ModelAPI_FeatureUpdatedMessage(theEvent, 0)
+Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(
+ const ObjectPtr& theObject,
+ const Events_ID& theEvent) : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
{
- if (theFeature) myFeatures.insert(theFeature);
+ if (theObject) myObjects.insert(theObject);
}
-std::set<FeaturePtr> Model_FeatureUpdatedMessage::features() const
+std::set<ObjectPtr> Model_ObjectUpdatedMessage::features() const
{
- return myFeatures;
+ return myObjects;
}
-Events_MessageGroup* Model_FeatureUpdatedMessage::newEmpty()
+Events_MessageGroup* Model_ObjectUpdatedMessage::newEmpty()
{
- FeaturePtr anEmptyFeature;
- return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
+ ObjectPtr anEmptyObject;
+ return new Model_ObjectUpdatedMessage(anEmptyObject, eventID());
}
-void Model_FeatureUpdatedMessage::Join(Events_MessageGroup& theJoined)
+void Model_ObjectUpdatedMessage::Join(Events_MessageGroup& theJoined)
{
- Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
- std::set<FeaturePtr >::iterator aFIter = aJoined->myFeatures.begin();
- for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
- myFeatures.insert(*aFIter);
+ Model_ObjectUpdatedMessage* aJoined = dynamic_cast<Model_ObjectUpdatedMessage*>(&theJoined);
+ std::set<ObjectPtr >::iterator aFIter = aJoined->myObjects.begin();
+ for(; aFIter != aJoined->myObjects.end(); aFIter++) {
+ myObjects.insert(*aFIter);
}
}
/////////////////////// DELETED MESSAGE /////////////////////////////
-Model_FeatureDeletedMessage::Model_FeatureDeletedMessage(
+Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
- : ModelAPI_FeatureDeletedMessage(messageId(), 0), myDoc(theDoc)
+ : ModelAPI_ObjectDeletedMessage(messageId(), 0), myDoc(theDoc)
{
if (!theGroup.empty())
myGroups.insert(theGroup);
}
-Events_MessageGroup* Model_FeatureDeletedMessage::newEmpty()
+Events_MessageGroup* Model_ObjectDeletedMessage::newEmpty()
{
- return new Model_FeatureDeletedMessage(myDoc, "");
+ return new Model_ObjectDeletedMessage(myDoc, "");
}
-const Events_ID Model_FeatureDeletedMessage::messageId()
+const Events_ID Model_ObjectDeletedMessage::messageId()
{
- static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
+ static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
return MY_ID;
}
-void Model_FeatureDeletedMessage::Join(Events_MessageGroup& theJoined)
+void Model_ObjectDeletedMessage::Join(Events_MessageGroup& theJoined)
{
- Model_FeatureDeletedMessage* aJoined = dynamic_cast<Model_FeatureDeletedMessage*>(&theJoined);
+ Model_ObjectDeletedMessage* aJoined = dynamic_cast<Model_ObjectDeletedMessage*>(&theJoined);
std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
for(; aGIter != aJoined->myGroups.end(); aGIter++) {
myGroups.insert(*aGIter);
public:
/// creates created, updated or moved messages and sends to the loop
virtual void sendUpdated(
- const FeaturePtr& theFeature, const Events_ID& theEvent, const bool isGroupped = true) const;
+ const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped = true) const;
/// creates deleted message and sends to the loop
virtual void sendDeleted(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const;
};
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
-class Model_FeatureUpdatedMessage : public ModelAPI_FeatureUpdatedMessage {
- std::set<FeaturePtr> myFeatures; ///< which feature is changed
+class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage {
+ std::set<ObjectPtr> myObjects; ///< which feature is changed
/// Sender is not important, all information is located in the feature.
/// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
- Model_FeatureUpdatedMessage(
- const FeaturePtr& theFeature,
+ Model_ObjectUpdatedMessage(
+ const ObjectPtr& theObject,
const Events_ID& theEvent);
friend class Model_EventCreator;
public:
/// Returns the feature that has been updated
- virtual std::set<FeaturePtr> features() const;
+ virtual std::set<ObjectPtr> features() const;
//! Creates a new empty group (to store it in the loop before flush)
virtual Events_MessageGroup* newEmpty();
};
/// Message that feature was deleted (used for Object Browser update)
-class Model_FeatureDeletedMessage : public ModelAPI_FeatureDeletedMessage {
+class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage {
boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
std::set<std::string> myGroups; ///< group identifiers that contained the deleted feature
/// Use ModelAPI for creation of this event.
- Model_FeatureDeletedMessage(
+ Model_ObjectDeletedMessage(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup);
friend class Model_EventCreator;
+++ /dev/null
-// File: Model_Object.cpp
-// Created: 19 May 2014
-// Author: Mikhail PONIKAROV
-
-#include "Model_Object.h"
-#include <TCollection_AsciiString.hxx>
-#include "Model_Events.h"
-#include <Events_Loop.h>
-
-FeaturePtr Model_Object::featureRef()
-{
- return myRef;
-}
-
-std::string Model_Object::getName()
-{
- return TCollection_AsciiString(myName->Get()).ToCString();
-}
-
-void Model_Object::setName(std::string theName)
-{
- if (myName->Get() != theName.c_str()) {
- myName->Set(theName.c_str());
- /*
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(boost::shared_ptr<ModelAPI_Object>(this), anEvent);
- Events_Loop::loop()->send(aMsg, false);
- */
- }
-}
-
-Model_Object::Model_Object(FeaturePtr theRef,
- Handle_TDataStd_Name theName)
- : myRef(theRef), myName(theName)
-{
-}
+++ /dev/null
-// File: Model_Object.hxx
-// Created: 19 May 2014
-// Author: Mikhail PONIKAROV
-
-#ifndef Model_Object_HeaderFile
-#define Model_Object_HeaderFile
-
-#include <Model.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Document.h>
-
-#include <TDataStd_Name.hxx>
-
-/**\class ModelAPI_Object
- * \ingroup DataModel
- * \brief Represents the result of some feature in the object browser
- * under the specific folder. Just a reference to specific feature-operation
- * with possibility to rename it.
- */
-class Model_Object : public ModelAPI_Object
-{
- FeaturePtr myRef; ///< the referenced feature
- Handle_TDataStd_Name myName; ///< the name of this object that may be changed
-public:
- /// Reference to the feature-operation that produces this object
- MODEL_EXPORT virtual FeaturePtr featureRef();
-
- /// Returns the name of this object (by default equal to the name of feature)
- MODEL_EXPORT virtual std::string getName();
-
- /// Defines the name of the object
- MODEL_EXPORT virtual void setName(std::string theName);
-
- /// Returns the kind of a feature (like "Point")
- MODEL_EXPORT virtual const std::string& getKind() {return myRef->getKind();}
-
- /// Returns to which group in the document must be added feature
- MODEL_EXPORT virtual const std::string& getGroup() {return FEATURES_GROUP;}
-
- /// Returns document this feature belongs to
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
- {return myRef->document();}
-
- /// Returns true if feature refers to the same model data instance
- MODEL_EXPORT virtual bool isSame(const FeaturePtr& theFeature)
- {
- boost::shared_ptr<Model_Object> anObj = boost::dynamic_pointer_cast<Model_Object>(theFeature);
- return anObj && myRef == anObj->myRef;
- }
-
- /// It is just a reference: don't init attributes
- MODEL_EXPORT virtual void initAttributes() {}
-
- /// It is just a reference: don't execute
- MODEL_EXPORT virtual void execute() {}
-
-private:
-
- /// Constructor fully defines this object
- Model_Object(FeaturePtr theRef, Handle_TDataStd_Name theName);
-
- friend class Model_Document;
-};
-
-#endif
} else {
Events_Error::send(string("Can not load plugin '") + myCurrentPluginName + "'");
}
+ } else {
+ Events_Error::send(string("Feature '") + theFeatureID + "' not found in any plugin");
}
return FeaturePtr(); // return nothing
Events_Loop* aLoop = Events_Loop::loop();
static Events_ID FeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
aLoop->registerListener(this, FeatureEvent);
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
}
void Model_PluginManager::processEvent(const Events_Message* theMessage)
--- /dev/null
+// File: Model_ResultBody.cpp
+// Created: 08 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultBody.h>
+#include <Model_Data.h>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
+
+Model_ResultBody::Model_ResultBody(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+ : myOwner(theFeature)
+{
+}
+
+void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ // TODO: to add the naming mechanism for shape storage in the next iteration
+ TNaming_Builder aBuilder(aShapeLab);
+ 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_ResultBody::shape()
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ Handle(TNaming_NamedShape) aName;
+ if (aShapeLab.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>();
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
+{
+ return myOwner;
+}
--- /dev/null
+// File: Model_ResultBody.h
+// Created: 08 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultBody_HeaderFile
+#define Model_ResultBody_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_ResultBody.h>
+
+/**\class ModelAPI_ResultBody
+ * \ingroup DataModel
+ * \brief The body (shape) result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * May provide really huge results, so, working with this kind
+ * of result must be optimized.
+ */
+class Model_ResultBody : public ModelAPI_ResultBody
+{
+ boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
+public:
+ /// 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();
+ /// Returns the source feature of this result
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
+
+protected:
+ /// Makes a body on the given feature
+ Model_ResultBody(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ friend class Model_Document;
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultConstruction.cpp
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultConstruction.h>
+
+void Model_ResultConstruction::setShape(boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+ myShape = theShape;
+}
+
+boost::shared_ptr<GeomAPI_Shape>& Model_ResultConstruction::shape()
+{
+ return myShape;
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_ResultConstruction::owner()
+{
+ return myOwner;
+}
+
+Model_ResultConstruction::Model_ResultConstruction(
+ const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+ : myOwner(theFeature)
+{
+}
--- /dev/null
+// File: ModelAPI_ResultConstruction.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultConstruction_HeaderFile
+#define Model_ResultConstruction_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_ResultConstruction.h>
+
+/**\class ModelAPI_ResultConstruction
+ * \ingroup DataModel
+ * \brief The construction element result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * Intermediate, light result that in many cases produces a result on the fly.
+ */
+class Model_ResultConstruction : public ModelAPI_ResultConstruction
+{
+ boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
+ boost::shared_ptr<GeomAPI_Shape> myShape; ///< shape of this result created "on the fly"
+public:
+ /// Returns the group identifier of this result
+ virtual std::string group()
+ {static std::string MY_GROUP = "Construction"; return MY_GROUP;}
+ /// Sets the result
+ MODEL_EXPORT virtual void setShape(boost::shared_ptr<GeomAPI_Shape> theShape);
+ /// Returns the shape-result produced by this feature
+ MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape>& shape();
+ /// Returns the source feature of this result
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
+
+protected:
+ /// Makes a body on the given feature
+ Model_ResultConstruction();
+
+ friend class Model_Document;
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultPart.cpp
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultPart.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+
+boost::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
+{
+ return data()->docRef("PartDocument")->value();
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
+{
+ return boost::shared_ptr<ModelAPI_Feature>(); // return empty pointer
+}
+
+Model_ResultPart::Model_ResultPart(
+const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+{
+}
--- /dev/null
+// File: ModelAPI_ResultPart.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultPart_HeaderFile
+#define Model_ResultPart_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_ResultPart.h>
+
+/**\class ModelAPI_ResultPart
+ * \ingroup DataModel
+ * \brief The Part document, result of a creation of new part feature.
+ *
+ * This result leaves without feature: no parametricity for this element,
+ * only add/remove, undo/redo.
+ */
+class Model_ResultPart : public ModelAPI_ResultPart
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string group()
+ {static std::string MY_GROUP = "Parts"; return MY_GROUP;}
+ /// Returns the part-document of this result
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> partDoc();
+ /// Part has no stored feature: this method returns NULL
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
+
+protected:
+ /// makes a result on a temporary feature (an action)
+ Model_ResultPart(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ friend class Model_Document;
+};
+
+#endif
Model_Update::Model_Update()
{
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
void Model_Update::processEvent(const Events_Message* theMessage)
{
- const ModelAPI_FeatureUpdatedMessage* aMsg =
- dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
+ const ModelAPI_ObjectUpdatedMessage* aMsg =
+ dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
myInitial = aMsg->features();
// collect all documents involved into the update
set<boost::shared_ptr<ModelAPI_Document> > aDocs;
- set<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myInitial.begin();
+ set<boost::shared_ptr<ModelAPI_Object> >::iterator aFIter = myInitial.begin();
for(; aFIter != myInitial.end(); aFIter++) {
aDocs.insert((*aFIter)->document());
}
for(; aDIter != aDocs.end(); aDIter++) {
int aNbFeatures = (*aDIter)->size(FEATURES_GROUP);
for(int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*aDIter)->feature(FEATURES_GROUP, aFIndex);
+ boost::shared_ptr<ModelAPI_Feature> aFeature =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>((*aDIter)->object(FEATURES_GROUP, aFIndex));
if (aFeature)
updateFeature(aFeature);
}
}
myUpdated.clear();
// flush
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_FEATURE_TO_REDISPLAY);
+ static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
Events_Loop::loop()->flush(EVENT_DISP);
}
bool anExecute = aMustbeUpdated || myInitial.find(theFeature) != myInitial.end();
if (anExecute) {
theFeature->execute();
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_FEATURE_TO_REDISPLAY);
+ static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
}
myUpdated[theFeature] = anExecute;
#include <set>
#include <map>
+class ModelAPI_Object;
class ModelAPI_Feature;
/**\class Model_Update
class Model_Update : public Events_Listener
{
///< initial set of updated features that must be processed
- std::set<boost::shared_ptr<ModelAPI_Feature> > myInitial;
+ std::set<boost::shared_ptr<ModelAPI_Object> > myInitial;
///< already updated and processed features and modificated feature flag
- std::map<boost::shared_ptr<ModelAPI_Feature>, bool> myUpdated;
+ std::map<boost::shared_ptr<ModelAPI_Object>, bool> myUpdated;
public:
/// Is called only once, on startup of the application
Model_Update();
ModelAPI_Events.h
ModelAPI_Validator.h
ModelAPI_FeatureValidator.h
+ ModelAPI_Result.h
+ ModelAPI_ResultBody.h
+ ModelAPI_ResultConstruction.h
+ ModelAPI_ResultPart.h
)
SET(PROJECT_SOURCES
#include <string>
#include <boost/shared_ptr.hpp>
-class ModelAPI_Feature;
+class ModelAPI_Object;
/**\class ModelAPI_Attribute
* \ingroup DataModel
class ModelAPI_Attribute
{
///< needed here to emit signal that feature changed on change of the attribute
- boost::shared_ptr<ModelAPI_Feature> myFeature;
+ boost::shared_ptr<ModelAPI_Object> myObject;
protected: // accessible from the attributes
bool myIsInitialized;
public:
MODELAPI_EXPORT virtual ~ModelAPI_Attribute() {}
/// Sets the owner of this attribute
- MODELAPI_EXPORT void setFeature(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
- {myFeature = theFeature;}
+ MODELAPI_EXPORT void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+ {myObject = theObject;}
/// Returns the owner of this attribute
- MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Feature>& owner()
- {return myFeature;}
+ MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Object>& owner()
+ {return myObject;}
/// Returns true if attribute was initialized by some value
MODELAPI_EXPORT bool isInitialized() {return myIsInitialized;}
public:
/// Returns the name of the feature visible by the user in the object browser
- virtual std::string getName() = 0;
+ virtual std::string name() = 0;
/// Defines the name of the feature visible by the user in the object browser
virtual void setName(std::string theName) = 0;
/// 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
#include <vector>
class ModelAPI_Feature;
+class ModelAPI_Object;
+class ModelAPI_Result;
+class ModelAPI_ResultConstruction;
/// Common groups identifiers
/// Group of parameters
static const std::string CONSTRUCTIONS_GROUP = "Construction";
/// Group of parts
static const std::string PARTS_GROUP = "Parts";
+/// Group of bodies
+static const std::string BODIES_GROUP = "Bodies";
/// All created fetaures of the document (a history)
static const std::string FEATURES_GROUP = "Features";
//! \param theFileName full name of the file to load
//! \param theStudyID identifier of the SALOME study to associate with loaded file
//! \returns true if file was loaded successfully
- MODELAPI_EXPORT virtual bool load(const char* theFileName) = 0;
+ virtual bool load(const char* theFileName) = 0;
//! Saves the OCAF document to the file.
//! \param theFileName full name of the file to store
//! \returns true if file was stored successfully
- MODELAPI_EXPORT virtual bool save(const char* theFileName) = 0;
+ virtual bool save(const char* theFileName) = 0;
//! Removes document data
- MODELAPI_EXPORT virtual void close() = 0;
+ virtual void close() = 0;
//! Starts a new operation (opens a tansaction)
- MODELAPI_EXPORT virtual void startOperation() = 0;
+ virtual void startOperation() = 0;
//! Finishes the previously started operation (closes the transaction)
- MODELAPI_EXPORT virtual void finishOperation() = 0;
+ virtual void finishOperation() = 0;
//! Aborts the operation
- MODELAPI_EXPORT virtual void abortOperation() = 0;
+ virtual void abortOperation() = 0;
//! Returns true if operation has been started, but not yet finished or aborted
- MODELAPI_EXPORT virtual bool isOperation() = 0;
+ virtual bool isOperation() = 0;
//! Returns true if document was modified (since creation/opening)
- MODELAPI_EXPORT virtual bool isModified() = 0;
+ virtual bool isModified() = 0;
//! Returns True if there are available Undos
- MODELAPI_EXPORT virtual bool canUndo() = 0;
+ virtual bool canUndo() = 0;
//! Undoes last operation
- MODELAPI_EXPORT virtual void undo() = 0;
+ virtual void undo() = 0;
//! Returns True if there are available Redos
- MODELAPI_EXPORT virtual bool canRedo() = 0;
+ virtual bool canRedo() = 0;
//! Redoes last operation
- MODELAPI_EXPORT virtual void redo() = 0;
+ virtual void redo() = 0;
//! Adds to the document the new feature of the given feature id
- //! \param creates feature and puts it in the document
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+ //! \param creates feature and puts it in the document (if it is not action)
+ virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
//! Removes the feature from the document
- MODELAPI_EXPORT virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document>
+ virtual boost::shared_ptr<ModelAPI_Document>
subDocument(std::string theDocID) = 0;
- ///! Returns the id of hte document
- MODELAPI_EXPORT virtual const std::string& id() const = 0;
+ ///! Returns the id of the document
+ virtual const std::string& id() const = 0;
- //! Returns the feature in the group by the index (started from zero)
- //! \param theGroupID group that contains a feature
+ //! Returns the object in the group by the index (started from zero)
+ //! \param theGroupID group that contains an object
//! \param theIndex zero-based index of feature in the group
- //! \param isOperation if it is true, returns feature (not Object)
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
- feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false) = 0;
+ virtual boost::shared_ptr<ModelAPI_Object>
+ object(const std::string& theGroupID, const int theIndex) = 0;
- //! Returns the number of features in the group
- MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0;
+ //! Returns the number of objects in the group of objects
+ virtual int size(const std::string& theGroupID) = 0;
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Document() {}
+ /// Creates a construction cresults
+ virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction() = 0;
+
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
#include <string>
#include <set>
-#include "ModelAPI_Feature.h"
+#include "ModelAPI_Object.h"
class ModelAPI_Document;
-/// Event ID that feature is created (comes with ModelAPI_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_CREATED = "FeatureCreated";
-/// Event ID that data of feature is updated (comes with Model_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
-/// Event ID that data of feature is deleted (comes with Model_FeatureDeletedMessage)
-static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
-/// Event ID that data of feature is updated (comes with ModelAPI_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_MOVED = "FeaturesMoved";
-/// Event ID that visualization must be redisplayed (comes with ModelAPI_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_TO_REDISPLAY = "FeaturesToRedisplay";
-/// Event ID that visualization must be redisplayed (comes with ModelAPI_FeatureUpdatedMessage)
+/// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
+/// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
+/// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
+static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
+/// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
+/// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
+/// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
-class ModelAPI_FeatureUpdatedMessage : public Events_MessageGroup {
+class ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup {
protected:
- ModelAPI_FeatureUpdatedMessage(const Events_ID theID, const void* theSender = 0)
+ ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0)
: Events_MessageGroup(theID, theSender) {}
public:
/// Returns the feature that has been updated
- virtual std::set<FeaturePtr> features() const = 0;
+ virtual std::set<ObjectPtr> features() const = 0;
//! Creates a new empty group (to store it in the loop before flush)
virtual Events_MessageGroup* newEmpty() = 0;
};
/// Message that feature was deleted (used for Object Browser update)
-class ModelAPI_FeatureDeletedMessage : public Events_MessageGroup {
+class ModelAPI_ObjectDeletedMessage : public Events_MessageGroup {
protected:
- ModelAPI_FeatureDeletedMessage(const Events_ID theID, const void* theSender = 0)
+ ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0)
: Events_MessageGroup(theID, theSender) {}
public:
class MODELAPI_EXPORT ModelAPI_EventCreator {
public:
/// creates created, updated or moved messages and sends to the loop
- virtual void sendUpdated(const FeaturePtr& theFeature, const Events_ID& theEvent,
+ virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
const bool isGroupped = true) const = 0;
/// creates deleted message and sends to the loop
virtual void sendDeleted(
#ifndef ModelAPI_Feature_HeaderFile
#define ModelAPI_Feature_HeaderFile
-#include "ModelAPI.h"
+#include "ModelAPI_Object.h"
#include "ModelAPI_PluginManager.h"
#include <string>
+#include <list>
#include <boost/shared_ptr.hpp>
class ModelAPI_Data;
class ModelAPI_Document;
+class ModelAPI_Result;
/**\class ModelAPI_Feature
* \ingroup DataModel
- * \brief Functionality of the model object: to update result,
- * to initialize attributes, etc.
+ * \brief Feature function that represents the particular functionality
+ * of this operation. Produces results by the arguments.
*/
-class ModelAPI_Feature
+class ModelAPI_Feature : public ModelAPI_Object
{
- boost::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
- boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
-
+ ///< list of current results of this feature
+ std::list<boost::shared_ptr<ModelAPI_Result> > myResults;
public:
- /// Returns the kind of a feature (like "Point")
- MODELAPI_EXPORT virtual const std::string& getKind() = 0;
-
- /// Returns to which group in the document must be added feature
- MODELAPI_EXPORT virtual const std::string& getGroup() = 0;
+ /// Returns the unique kind of a feature (like "Point")
+ virtual const std::string& getKind() = 0;
/// Request for initialization of data model of the feature: adding all attributes
- MODELAPI_EXPORT virtual void initAttributes() = 0;
+ virtual void initAttributes() = 0;
- /// Computes or recomputes the result
- MODELAPI_EXPORT virtual void execute() = 0;
+ /// Computes or recomputes the results
+ virtual void execute() = 0;
- /// Returns true if this feature must be displayed in the history (top level of Part tree)
- MODELAPI_EXPORT virtual bool isInHistory() {return true;}
+ // returns the current results of the feature
+ std::list<boost::shared_ptr<ModelAPI_Result> >& results() {return myResults;}
/// Returns true if this feature must not be created: this is just an action
- /// that is not stored in the features history (like delete part).
- MODELAPI_EXPORT virtual bool isAction() {return false;}
-
- /// Returns the data manager of this feature
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Data> data() {return myData;}
+ /// that is not stored in the features history and data model (like "delete part").
+ virtual bool isAction() {return false;}
/// Must return document where the new feature must be added to
/// By default it is current document
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
+ virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
{return ModelAPI_PluginManager::get()->currentDocument();}
- /// Returns document this feature belongs to
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
- {return myDoc;}
-
- /// Returns true if feature refers to the same model data instance
- MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
- {return theFeature.get() == this;}
-
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Feature() {}
-
-protected:
- /// Use plugin manager for features creation: this method is
- /// defined here only for SWIG-wrapping
- ModelAPI_Feature()
- {}
-
- /// Sets the data manager of an object (document does)
- MODELAPI_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
- {myData = theData;}
- /// Sets the data manager of an object (document does)
- MODELAPI_EXPORT void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
-
- friend class Model_Document;
};
//! Pointer on feature object
typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
-
#endif
#ifndef ModelAPI_Object_HeaderFile
#define ModelAPI_Object_HeaderFile
-#include "ModelAPI_Feature.h"
+#include "ModelAPI.h"
#include <boost/shared_ptr.hpp>
+class ModelAPI_Data;
+class ModelAPI_Document;
+
/**\class ModelAPI_Object
* \ingroup DataModel
- * \brief Represents the result of some feature in the object browser
- * under the specific folder. Just a reference to specific feature-operation
- * with possibility to rename it.
+ * \brief Represents any object in the data model and in the object browser.
+ *
+ * It may be feature or result of the feature. User just may set name for it
+ * or change this name later. Generic class for Feature, Body, Parameter and other
+ * objects related to the features and their results. Contains attributes of this
+ * object in the "Data".
*/
-class ModelAPI_Object : public ModelAPI_Feature
+class ModelAPI_Object
{
+ boost::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
+ boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
public:
+ /// By default object is displayed in the object browser.
+ virtual bool isInHistory() {return true;}
- /// It is never located in history
- MODELAPI_EXPORT virtual bool isInHistory() {return false;}
+ /// Returns the data manager of this object: attributes
+ virtual boost::shared_ptr<ModelAPI_Data> data() {return myData;}
- /// Reference to the feature-operation that produces this object
- MODELAPI_EXPORT virtual FeaturePtr featureRef() = 0;
+ /// Returns true if feature refers to the same data model instance
+ virtual bool isSame(const boost::shared_ptr<ModelAPI_Object>& theObject)
+ {return theObject.get() == this;}
- /// Returns the name of this object (by default equal to the name of feature)
- MODELAPI_EXPORT virtual std::string getName() = 0;
+ /// Returns document this feature belongs to
+ virtual boost::shared_ptr<ModelAPI_Document> document()
+ {return myDoc;}
- /// Defines the name of the object
- MODELAPI_EXPORT virtual void setName(std::string theName) = 0;
-};
+protected:
+ /// Sets the data manager of an object (document does)
+ virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
+ {myData = theData;}
+ /// Sets the data manager of an object (document does)
+ virtual void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
+
+ friend class Model_Document;
+};
typedef boost::shared_ptr<ModelAPI_Object> ObjectPtr;
--- /dev/null
+// File: ModelAPI_Result.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_Result_HeaderFile
+#define ModelAPI_Result_HeaderFile
+
+#include "ModelAPI_Object.h"
+
+class ModelAPI_Feature;
+
+/**\class ModelAPI_Result
+ * \ingroup DataModel
+ * \brief The result of a feature.
+ *
+ * A generic class that .
+ */
+class ModelAPI_Result : public ModelAPI_Object
+{
+public:
+ /// Returns the source feature of this result
+ //virtual boost::shared_ptr<ModelAPI_Feature> owner() = 0;
+
+ /// Returns the group identifier of this result
+ virtual std::string group() = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_Result> ResultPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultBody.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultBody_HeaderFile
+#define ModelAPI_ResultBody_HeaderFile
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+
+/**\class ModelAPI_ResultBody
+ * \ingroup DataModel
+ * \brief The body (shape) result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * May provide really huge results, so, working with this kind
+ * of result must be optimized.
+ */
+class ModelAPI_ResultBody : public ModelAPI_Result
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string group()
+ {static std::string MY_GROUP = "Bodies"; return MY_GROUP;}
+
+ /// 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;
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_ResultBody() {}
+
+protected:
+ /// Use plugin manager for features creation: this method is
+ /// defined here only for SWIG-wrapping
+ ModelAPI_ResultBody()
+ {}
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultBody> ResultBodyPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultConstruction.h
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultConstruction_HeaderFile
+#define ModelAPI_ResultConstruction_HeaderFile
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+
+/**\class ModelAPI_ResultConstruction
+ * \ingroup DataModel
+ * \brief The construction element result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * Intermediate, light result that in many cases produces a result on the fly.
+ */
+class ModelAPI_ResultConstruction : public ModelAPI_Result
+{
+public:
+ /// Returns the shape-result produced by this feature
+ virtual boost::shared_ptr<GeomAPI_Shape>& shape() = 0;
+
+ /// Sets the result
+ virtual void setShape(boost::shared_ptr<GeomAPI_Shape> theShape) = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultConstruction> ResultConstructionPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultPart.h
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultPart_HeaderFile
+#define ModelAPI_ResultPart_HeaderFile
+
+#include "ModelAPI_Result.h"
+
+/**\class ModelAPI_ResultPart
+ * \ingroup DataModel
+ * \brief The Part document, result of a creation of new part feature.
+ *
+ * This result leaves without feature: no parametricity for this element,
+ * only add/remove, undo/redo.
+ */
+class ModelAPI_ResultPart : public ModelAPI_Result
+{
+public:
+ /// Returns the part-document of this result
+ virtual boost::shared_ptr<ModelAPI_Document> partDoc() = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultPart> ResultPart;
+
+#endif
void ModuleBase_Operation::flushUpdated()
{
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
void ModuleBase_Operation::flushCreated()
{
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
}
FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
if (aBool->value() != myCheckBox->isChecked()) {
aBool->setValue(myCheckBox->isChecked());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
return true;
}
AttributeDoublePtr aReal = aData->real(attributeID());
if (aReal->value() != mySpinBox->value()) {
aReal->setValue(mySpinBox->value());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
return true;
}
ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
aRef->setFeature(myFeature);
theFeature->execute();
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
return true;
}
aRef->setAttr(myAttribute);
theFeature->execute();
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
return true;
}
ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
bool isBlocked = that->blockSignals(true);
aPoint->setValue(myXSpin->value(), myYSpin->value());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
that->blockSignals(isBlocked);
return true;
FeaturePtr aFeature = aRef->value();
if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
aRef->setValue(mySelectedFeature);
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
return true;
}
: myModule(theModule)
{
Events_Loop* aLoop = Events_Loop::loop();
- aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ aLoop->registerListener(this, aLoop->eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
}
PartSet_Listener::~PartSet_Listener()
void PartSet_Listener::processEvent(const Events_Message* theMessage)
{
QString aType = QString(theMessage->eventID().eventText());
- if (aType == EVENT_FEATURE_UPDATED ||
- aType == EVENT_FEATURE_CREATED)
+ if (aType == EVENT_OBJECT_UPDATED ||
+ aType == EVENT_OBJECT_CREATED)
{
- const ModelAPI_FeatureUpdatedMessage* aUpdMsg =
- dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
+ const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
+ dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
std::set<FeaturePtr > aFeatures = aUpdMsg->features();
std::set<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = *anIt;
if (myModule->workshop()->displayer()->isVisible(aFeature) ||
- aType == EVENT_FEATURE_CREATED) {
+ aType == EVENT_OBJECT_CREATED) {
myModule->visualizePreview(aFeature, true, false);
- //if (aType == EVENT_FEATURE_CREATED)
+ //if (aType == EVENT_OBJECT_CREATED)
myModule->activateFeature(aFeature, true);
}
}
myModule->workshop()->displayer()->updateViewer();
}
- if (aType == EVENT_FEATURE_DELETED)
+ if (aType == EVENT_OBJECT_DELETED)
{
const ModelAPI_FeatureDeletedMessage* aDelMsg =
dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
void PartSet_OperationFeatureEdit::sendFeatures()
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
FeaturePtr aFeature = feature();
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
void PartSet_OperationFeatureEditMulti::sendFeatures()
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
std::list<FeaturePtr > aFeatures;
std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
#include "SketchPlugin_Arc.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Pnt2d.h>
-
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
-
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
}
void SketchPlugin_Arc::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Arc::preview()
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
aShapes.push_back(aCircleShape);
}
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- setPreview(aCompound);
+ // store the result
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
+ aConstr->setShape(aCompound);
+ results().push_back(aConstr);
}
}
- return getPreview();
-}
-
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Arc::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
}
void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_ARC_KIND; return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
- /// Creates a new part document if needed
+ /// Creates an arc-shape
SKETCHPLUGIN_EXPORT virtual void execute();
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
#include "SketchPlugin_Circle.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pnt2d.h>
-
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
-
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
-
#include <ModelAPI_AttributeDouble.h>
SketchPlugin_Circle::SketchPlugin_Circle()
data()->addAttribute(CIRCLE_ATTR_RADIUS, ModelAPI_AttributeDouble::type());
}
-void SketchPlugin_Circle::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
+void SketchPlugin_Circle::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
}
}
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- setPreview(aCompound);
+ // store the result
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult)->setShape(aCompound);
}
- return getPreview();
-}
-
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Circle::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
}
void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CIRCLE_KIND; return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
{
return thePrevious;
}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Constraint::preview()
-{
- return getPreview();
-}
-
class SketchPlugin_Constraint: public SketchPlugin_Feature
{
public:
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/** \brief Adds sub-feature of the higher level feature (sub-element of the sketch)
* \param theFeature sub-feature
*/
SKETCHPLUGIN_EXPORT virtual const void addSub(
const FeaturePtr& theFeature) {}
- /// \brief Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
}
-void SketchPlugin_ConstraintCoincidence::execute()
+void SketchPlugin_ConstraintCoincidence::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
}
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CONSTRAINT_COINCIDENCE_KIND; return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// \brief Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
}
-void SketchPlugin_ConstraintDistance::execute()
+void SketchPlugin_ConstraintDistance::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
boost::shared_ptr<ModelAPI_Data> aData = data();
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CONSTRAINT_DISTANCE_KIND; return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// \brief Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
}
-void SketchPlugin_ConstraintLength::execute()
+void SketchPlugin_ConstraintLength::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() &&
!data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) {
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CONSTRAINT_LENGTH_KIND; return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// \brief Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
}
-void SketchPlugin_ConstraintParallel::execute()
+void SketchPlugin_ConstraintParallel::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
}
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintParallel::preview()
-{
- /// \todo Preview for parallel constraint
- return getPreview();
-}
-
-
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintParallel::getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CONSTRAINT_PARALLEL_KIND; return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// \brief Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
}
-void SketchPlugin_ConstraintPerpendicular::execute()
+void SketchPlugin_ConstraintPerpendicular::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
}
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintPerpendicular::preview()
-{
- /// \todo Preview for perpendicular constraint
- return getPreview();
-}
-
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintPerpendicular::getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CONSTRAINT_PERPENDICULAR_KIND; return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// \brief Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
}
-void SketchPlugin_ConstraintRadius::execute()
+void SketchPlugin_ConstraintRadius::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() &&
!data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) {
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_CONSTRAINT_RADIUS_KIND; return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// \brief Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
mySketch = 0;
}
-void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
-{
- myPreview = theShape;
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::getPreview() const
-{
- return myPreview;
-}
-
SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
{
if (!mySketch) {
int aSketches = document()->size("Construction");
for(int a = 0; a < aSketches && !mySketch; a++) {
boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
- dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
+ dynamic_pointer_cast<SketchPlugin_Sketch>(document()->object("Construction", a));
if (aSketch) {
std::list<FeaturePtr > aList =
aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Feature::prepareAISShape(
boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
+ document()->result();
boost::shared_ptr<GeomAPI_Shape> aPreview = preview();
boost::shared_ptr<GeomAPI_AISObject> aResult = thePrevious;
if (!aResult)
#include <ModelAPI_Feature.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Document.h>
class SketchPlugin_Sketch;
class GeomAPI_Pnt2d;
class SketchPlugin_Feature: public ModelAPI_Feature
{
public:
- /// Returns the sketch preview
- /// \param theSketch the owner of this feature
- /// \return the built preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
+ /// Returns the type of the feature result: it is allways construction element
+ virtual const std::string& getResultType() {return CONSTRUCTIONS_GROUP;}
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
protected:
- /// Set the shape to the internal preview field
- /// \param theShape a preview shape
- void setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape); ///< the preview shape
- /// Return the shape from the internal preview field
- /// \return theShape a preview shape
- const boost::shared_ptr<GeomAPI_Shape>& getPreview() const;
- /// Common method for other features to produce AIS shape
- boost::shared_ptr<GeomAPI_AISObject> prepareAISShape(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
/// Sets the higher-level feature for the sub-feature (sketch for line)
void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
/// Returns the sketch of this feature
#include "SketchPlugin_Line.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Lin2d.h>
data()->addAttribute(LINE_ATTR_END, GeomDataAPI_Point2D::type());
}
-void SketchPlugin_Line::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Line::preview()
+void SketchPlugin_Line::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
// make linear edge
boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
- setPreview(anEdge);
+ // store the result
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult)->setShape(anEdge);
}
}
- return getPreview();
}
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Line::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
-}
-
-
void SketchPlugin_Line::move(double theDeltaX, double theDeltaY)
{
boost::shared_ptr<ModelAPI_Data> aData = data();
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_LINE_KIND; return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pnt2d.h>
data()->addAttribute(POINT_ATTR_COORD, GeomDataAPI_Point2D::type());
}
-void SketchPlugin_Point::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Point::preview()
+void SketchPlugin_Point::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
// make a visible point
boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
- setPreview(aPointShape);
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult)->setShape(aPointShape);
}
- return getPreview();
-}
-
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Point::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
}
void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SKETCH_POINT_KIND; return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
-
/// Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_SketchBuilder.h>
+#include <ModelAPI_ResultConstruction.h>
const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color
data()->addAttribute(SKETCH_ATTR_FEATURES, ModelAPI_AttributeRefList::type());
}
-void SketchPlugin_Sketch::execute()
+void SketchPlugin_Sketch::execute(boost::shared_ptr<ModelAPI_Result>& theResult)
{
+ if (!isPlaneSet()) {
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+
+ addPlane(1, 0, 0, aFaces); // YZ plane
+ addPlane(0, 1, 0, aFaces); // XZ plane
+ addPlane(0, 0, 1, aFaces); // XY plane
+ boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult)->setShape(aCompound);
+ return;
+ }
if (!data()->isValid())
return ;
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
std::list< boost::shared_ptr<GeomAPI_Shape> > aFeaturesPreview;
for (; anIt != aLast; anIt++) {
aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
- boost::shared_ptr<GeomAPI_Shape> aPreview = aFeature->preview();
- if (aPreview)
- aFeaturesPreview.push_back(aPreview);
+ boost::shared_ptr<ModelAPI_ResultConstruction> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(document()->result(aFeature));
+ if (aRes) {
+ boost::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+ if (aShape)
+ aFeaturesPreview.push_back(aShape);
+ }
}
if (aFeaturesPreview.empty())
aLoops.insert(aLoops.end(), aWires.begin(), aWires.end());
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
- data()->store(aCompound);
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult)->setShape(aCompound);
}
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Sketch::getAISObject(
return anAIS;
}
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
-{
- if (isPlaneSet()) {
- setPreview(boost::shared_ptr<GeomAPI_Shape>());
- }
- else {
- std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
-
- addPlane(1, 0, 0, aFaces); // YZ plane
- addPlane(0, 1, 0, aFaces); // XZ plane
- addPlane(0, 0, 1, aFaces); // XY plane
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
- setPreview(aCompound);
- }
- return getPreview();
-}
-
const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
{
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
{static std::string MY_GROUP = "Construction"; return MY_GROUP;}
/// Creates a new part document if needed
- SKETCHPLUGIN_EXPORT virtual void execute();
+ SKETCHPLUGIN_EXPORT virtual void execute(boost::shared_ptr<ModelAPI_Result>& theResult);
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
if (isUpd)
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent);
break;
}
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
if (aRefAttr && aRefAttr->isFeature() && aRefAttr->feature() == theFeature)
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent);
break;
}
myGroups.clear();
// Register in event loop
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_MOVED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_MOVED));
}
SketchSolver_ConstraintManager::~SketchSolver_ConstraintManager()
// ============================================================================
void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessage)
{
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED) ||
- theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED) ||
- theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED))
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED) ||
+ theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED) ||
+ theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED))
{
- const ModelAPI_FeatureUpdatedMessage* anUpdateMsg =
- dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
+ const ModelAPI_ObjectUpdatedMessage* anUpdateMsg =
+ dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
std::set< FeaturePtr > aFeatures = anUpdateMsg->features();
bool isModifiedEvt =
- theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED);
+ theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
if (!isModifiedEvt)
{
std::set< FeaturePtr >::iterator aFeatIter;
// Solve the set of constraints
resolveConstraints();
}
- else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED))
+ else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED))
{
const ModelAPI_FeatureDeletedMessage* aDeleteMsg =
dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
(*aGroupIter)->resolveConstraints();
// Features may be updated => send events
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
: QAbstractItemModel(theParent), myActivePart(0)
{
// Register in event loop
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
// Create a top part of data tree model
myModel = new XGUI_TopDataModel(this);
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
// Created object event *******************
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
std::set<FeaturePtr> aFeatures = aUpdMsg->features();
}
}
// Deleted object event ***********************
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
+ } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
DocumentPtr aDoc = aUpdMsg->document();
std::set<std::string> aGroups = aUpdMsg->groups();
}
}
// Deleted object event ***********************
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
+ } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
//const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
//FeaturePtr aFeature = aUpdMsg->feature();
//DocumentPtr aDoc = aFeature->document();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LOADED));
// TODO Is it good to use non standard event within workshop?
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_TO_REDISPLAY));
activateModule();
}
// Process creation of Part
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
onFeatureCreatedMsg(aUpdMsg);
}
//Update property panel on corresponding message. If there is no current operation (no
//property panel), or received message has different feature to the current - do nothing.
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
const Model_FeatureUpdatedMessage* anUpdateMsg =
dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
onFeatureUpdatedMsg(anUpdateMsg);