#include <Model_Document.h>
#include <Model_Data.h>
#include <Model_Application.h>
-#include <Model_PluginManager.h>
+#include <Model_Session.h>
#include <Model_Events.h>
#include <Model_ResultPart.h>
#include <Model_ResultConstruction.h>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Comment.hxx>
+#include <TDataStd_UAttribute.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <TDataStd_ReferenceArray.hxx>
#include <TDataStd_HLabelArray1.hxx>
static const int TAG_FEATURE_ARGUMENTS = 1; ///< where the arguments are located
static const int TAG_FEATURE_RESULTS = 2; ///< where the results are located
-Model_Document::Model_Document(const std::string theID)
- : myID(theID),
+Model_Document::Model_Document(const std::string theID, const std::string theKind)
+ : myID(theID), myKind(theKind),
myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
{
myDoc->SetUndoLimit(UNDO_LIMIT);
static TCollection_ExtendedString DocFileName(const char* theFileName, const std::string& theID)
{
TCollection_ExtendedString aPath((const Standard_CString) theFileName);
+ // remove end-separators
+ while(aPath.Length() && (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
+ aPath.Remove(aPath.Length());
aPath += _separator_;
aPath += theID.c_str();
aPath += ".cbf"; // standard binary file extension
bool Model_Document::load(const char* theFileName)
{
Handle(Model_Application) anApp = Model_Application::getApplication();
- if (this == Model_PluginManager::get()->rootDocument().get()) {
+ if (this == Model_Session::get()->moduleDocument().get()) {
anApp->setLoadPath(theFileName);
}
TCollection_ExtendedString aPath(DocFileName(theFileName, myID));
if (isError) {
switch (aStatus) {
case PCDM_RS_UnknownDocument:
- Events_Error::send(std::string("Can not open document: PCDM_RS_UnknownDocument"));
+ Events_Error::send(std::string("Can not open document: unknown format"));
break;
case PCDM_RS_AlreadyRetrieved:
- Events_Error::send(std::string("Can not open document: PCDM_RS_AlreadyRetrieved"));
+ Events_Error::send(std::string("Can not open document: already opened"));
break;
case PCDM_RS_AlreadyRetrievedAndModified:
Events_Error::send(
- std::string("Can not open document: PCDM_RS_AlreadyRetrievedAndModified"));
+ std::string("Can not open document: already opened and modified"));
break;
case PCDM_RS_NoDriver:
- Events_Error::send(std::string("Can not open document: PCDM_RS_NoDriver"));
+ Events_Error::send(std::string("Can not open document: driver library is not found"));
break;
case PCDM_RS_UnknownFileDriver:
- Events_Error::send(std::string("Can not open document: PCDM_RS_UnknownFileDriver"));
+ Events_Error::send(std::string("Can not open document: unknown driver for opening"));
break;
case PCDM_RS_OpenError:
- Events_Error::send(std::string("Can not open document: PCDM_RS_OpenError"));
+ Events_Error::send(std::string("Can not open document: file open error"));
break;
case PCDM_RS_NoVersion:
- Events_Error::send(std::string("Can not open document: PCDM_RS_NoVersion"));
+ Events_Error::send(std::string("Can not open document: invalid version"));
break;
case PCDM_RS_NoModel:
- Events_Error::send(std::string("Can not open document: PCDM_RS_NoModel"));
+ Events_Error::send(std::string("Can not open document: no data model"));
break;
case PCDM_RS_NoDocument:
- Events_Error::send(std::string("Can not open document: PCDM_RS_NoDocument"));
+ Events_Error::send(std::string("Can not open document: no document inside"));
break;
case PCDM_RS_FormatFailure:
- Events_Error::send(std::string("Can not open document: PCDM_RS_FormatFailure"));
+ Events_Error::send(std::string("Can not open document: format failure"));
break;
case PCDM_RS_TypeNotFoundInSchema:
- Events_Error::send(std::string("Can not open document: PCDM_RS_TypeNotFoundInSchema"));
+ Events_Error::send(std::string("Can not open document: invalid object"));
break;
case PCDM_RS_UnrecognizedFileFormat:
- Events_Error::send(std::string("Can not open document: PCDM_RS_UnrecognizedFileFormat"));
+ Events_Error::send(std::string("Can not open document: unrecognized file format"));
break;
case PCDM_RS_MakeFailure:
- Events_Error::send(std::string("Can not open document: PCDM_RS_MakeFailure"));
+ Events_Error::send(std::string("Can not open document: make failure"));
break;
case PCDM_RS_PermissionDenied:
- Events_Error::send(std::string("Can not open document: PCDM_RS_PermissionDenied"));
+ Events_Error::send(std::string("Can not open document: permission denied"));
break;
case PCDM_RS_DriverFailure:
- Events_Error::send(std::string("Can not open document: PCDM_RS_DriverFailure"));
+ Events_Error::send(std::string("Can not open document: driver failure"));
break;
default:
Events_Error::send(std::string("Can not open document: unknown error"));
return !isError;
}
-bool Model_Document::save(const char* theFileName)
+bool Model_Document::save(const char* theFileName, std::list<std::string>& theResults)
{
// create a directory in the root document if it is not yet exist
- if (this == Model_PluginManager::get()->rootDocument().get()) {
+ if (this == Model_Session::get()->moduleDocument().get()) {
#ifdef WIN32
CreateDirectory(theFileName, NULL);
#else
if (!isDone) {
switch (aStatus) {
case PCDM_SS_DriverFailure:
- Events_Error::send(std::string("Can not save document: PCDM_SS_DriverFailure"));
+ Events_Error::send(std::string("Can not save document: save driver-library failure"));
break;
case PCDM_SS_WriteFailure:
- Events_Error::send(std::string("Can not save document: PCDM_SS_WriteFailure"));
+ Events_Error::send(std::string("Can not save document: file writing failure"));
break;
case PCDM_SS_Failure:
default:
- Events_Error::send(std::string("Can not save document: PCDM_SS_Failure"));
+ Events_Error::send(std::string("Can not save document"));
break;
}
}
myTransactionsAfterSave = 0;
if (isDone) { // save also sub-documents if any
+ theResults.push_back(TCollection_AsciiString(aPath).ToCString());
std::set<std::string>::iterator aSubIter = mySubs.begin();
- for (; aSubIter != mySubs.end() && isDone; aSubIter++)
- isDone = subDocument(*aSubIter)->save(theFileName);
+ for (; aSubIter != mySubs.end() && isDone; aSubIter++) {
+ isDone = subDoc(*aSubIter)->save(theFileName, theResults);
+ }
}
return isDone;
}
void Model_Document::close()
{
- boost::shared_ptr<ModelAPI_PluginManager> aPM = Model_PluginManager::get();
- if (this != aPM->rootDocument().get() && this == aPM->currentDocument().get()) {
- aPM->setCurrentDocument(aPM->rootDocument());
+ boost::shared_ptr<ModelAPI_Session> aPM = Model_Session::get();
+ if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) {
+ aPM->setActiveDocument(aPM->moduleDocument());
}
// close all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- subDocument(*aSubIter)->close();
+ subDoc(*aSubIter)->close();
mySubs.clear();
// close this
/* do not close because it can be undoed
myNestedNum = 0;
myDoc->InitDeltaCompaction();
}
- myIsEmptyTr[myTransactionsAfterSave] = false;
+ myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand();
myTransactionsAfterSave++;
- myDoc->NewCommand();
+ myDoc->OpenCommand();
} else { // start the simple command
myDoc->NewCommand();
}
// new command for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- subDocument(*aSubIter)->startOperation();
+ subDoc(*aSubIter)->startOperation();
}
-void Model_Document::compactNested()
+bool Model_Document::compactNested()
{
bool allWasEmpty = true;
while (myNestedNum != -1) {
myIsEmptyTr[myTransactionsAfterSave] = allWasEmpty;
myTransactionsAfterSave++;
myDoc->PerformDeltaCompaction();
+ return !allWasEmpty;
}
void Model_Document::finishOperation()
{
- // just to be sure that everybody knows that changes were performed
+ // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
+ for (; aSubIter != mySubs.end(); aSubIter++)
+ subDoc(*aSubIter)->finishOperation();
+ // just to be sure that everybody knows that changes were performed
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
- boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
+ boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(false); // for nested transaction commit
- 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_TO_REDISPLAY));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ Events_Loop* aLoop = Events_Loop::loop();
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
- boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())
+ boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(true); // for nested transaction commit
if (myNestedNum != -1) // this nested transaction is owervritten
myTransactionsAfterSave++;
}
- // finish for all subs
- std::set<std::string>::iterator aSubIter = mySubs.begin();
- for (; aSubIter != mySubs.end(); aSubIter++)
- subDocument(*aSubIter)->finishOperation();
}
void Model_Document::abortOperation()
{
if (myNestedNum > 0 && !myDoc->HasOpenCommand()) { // abort all what was done in nested
// first compact all nested
- compactNested();
- // for nested it is undo and clear redos
- myDoc->Undo();
+ if (compactNested()) {
+ // for nested it is undo and clear redos
+ myDoc->Undo();
+ }
myDoc->ClearRedos();
myTransactionsAfterSave--;
myIsEmptyTr.erase(myTransactionsAfterSave);
// abort for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- subDocument(*aSubIter)->abortOperation();
+ subDoc(*aSubIter)->abortOperation();
}
bool Model_Document::isOperation()
bool Model_Document::isModified()
{
// is modified if at least one operation was commited and not undoed
- return myTransactionsAfterSave > 0;
+ return myTransactionsAfterSave > 0 || isOperation();
}
bool Model_Document::canUndo()
// check other subs contains operation that can be undoed
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- if (subDocument(*aSubIter)->canUndo())
+ if (subDoc(*aSubIter)->canUndo())
return true;
return false;
}
// undo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- subDocument(*aSubIter)->undo();
+ subDoc(*aSubIter)->undo();
}
bool Model_Document::canRedo()
// check other subs contains operation that can be redoed
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- if (subDocument(*aSubIter)->canRedo())
+ if (subDoc(*aSubIter)->canRedo())
return true;
return false;
}
// redo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- subDocument(*aSubIter)->redo();
+ subDoc(*aSubIter)->redo();
}
/// Appenad to the array of references a new referenced label
{
TDF_Label anEmptyLab;
FeaturePtr anEmptyFeature;
- FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
+ FeaturePtr aFeature = ModelAPI_Session::get()->createFeature(theID);
+ if (!aFeature)
+ return aFeature;
boost::shared_ptr<Model_Document> aDocToAdd = boost::dynamic_pointer_cast<Model_Document>(
aFeature->documentToAdd());
if (aFeature) {
// event: feature is added
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
+ } else { // feature must be executed
+ // no creation event => updater not working, problem with remove part
+ aFeature->execute();
}
}
return aFeature;
return aResult;
}
-void Model_Document::removeFeature(FeaturePtr theFeature)
+void Model_Document::removeFeature(FeaturePtr theFeature, const bool theCheck)
{
+ if (theCheck) {
+ // check the feature: it must have no depended objects on it
+ std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
+ for(; aResIter != theFeature->results().cend(); aResIter++) {
+ if (myConcealedResults.find(*aResIter) != myConcealedResults.end()) {
+ Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+ return;
+ }
+ }
+ NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myObjs);
+ for(; anObjIter.More(); anObjIter.Next()) {
+ DataPtr aData = anObjIter.Value()->data();
+ if (aData->referencesTo(theFeature)) {
+ Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+ return;
+ }
+ }
+ }
+
boost::shared_ptr<Model_Data> aData = boost::static_pointer_cast<Model_Data>(theFeature->data());
TDF_Label aFeatureLabel = aData->label().Father();
if (myObjs.IsBound(aFeatureLabel))
myObjs.UnBind(aFeatureLabel);
else
return; // not found feature => do not remove
-
+ // erase fields
+ theFeature->erase();
// erase all attributes under the label of feature
aFeatureLabel.ForgetAllAttributes();
// remove it from the references array
// event: feature is deleted
ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
+ /* this is in "erase"
// results of this feature must be redisplayed
static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), aRes->groupName());
}
+ */
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel)
return Model_Application::getApplication()->getDocument(theDocID);
}
+boost::shared_ptr<Model_Document> Model_Document::subDoc(std::string theDocID)
+{
+ // just store sub-document identifier here to manage it later
+ if (mySubs.find(theDocID) == mySubs.end())
+ mySubs.insert(theDocID);
+ return boost::dynamic_pointer_cast<Model_Document>(
+ Model_Application::getApplication()->getDocument(theDocID));
+}
+
ObjectPtr Model_Document::object(const std::string& theGroupID, const int theIndex,
const bool theHidden)
{
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
- if ((theHidden || (*aRIter)->isInHistory()) && (*aRIter)->groupName() == theGroupID) {
+ if ((*aRIter)->groupName() != theGroupID) continue;
+ bool isIn = theHidden;
+ if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
+ isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ }
+ if (isIn) {
if (anIndex == theIndex)
return *aRIter;
anIndex++;
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
- if ((theHidden || (*aRIter)->isInHistory()) && (*aRIter)->groupName() == theGroupID) {
- aResult++;
+ if ((*aRIter)->groupName() != theGroupID) continue;
+ bool isIn = theHidden;
+ if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
+ isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
}
+ if (isIn)
+ aResult++;
}
}
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
{
- boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(
- myID);
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ // after all updates, sends a message that groups of features were created or updated
+ boost::static_pointer_cast<Model_Session>(Model_Session::get())
+ ->setCheckTransactions(false);
+ Events_Loop* aLoop = Events_Loop::loop();
+ aLoop->activateFlushes(false);
+
// update all objects by checking are they of labels or not
std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
TDF_Label aFeatureLabel = aLabIter.Value()->Label();
if (!myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted
// create a feature
- FeaturePtr aNewObj = ModelAPI_PluginManager::get()->createFeature(
+ FeaturePtr aNewObj = ModelAPI_Session::get()->createFeature(
TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
.ToCString());
if (!aNewObj) { // somethig is wrong, most probably, the opened document has invalid structure
// 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
+
+ // update results of the appeared feature
+ updateResults(aNewObj);
} else { // nothing is changed, both iterators are incremented
- aKeptFeatures.insert(myObjs.Find(aFeatureLabel));
+ FeaturePtr aFeature = myObjs.Find(aFeatureLabel);
+ aKeptFeatures.insert(aFeature);
if (theMarkUpdated) {
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(myObjs.Find(aFeatureLabel), anEvent);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
}
+ updateResults(aFeature);
}
}
// execute new features to restore results: after features creation to make all references valid
if (aKeptFeatures.find(aFIter.Value()) == aKeptFeatures.end()
&& aNewFeatures.find(aFIter.Value()) == aNewFeatures.end()) {
FeaturePtr aFeature = aFIter.Value();
- TDF_Label aLab = aFIter.Key();
- aFIter.Next();
- myObjs.UnBind(aLab);
// event: model is updated
- if (aFeature->isInHistory()) {
+ //if (aFeature->isInHistory()) {
ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Feature::group());
- }
+ //}
// results of this feature must be redisplayed (hided)
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ /*
for (; aRIter != aResults.cend(); aRIter++) {
boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
//aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
ModelAPI_EventCreator::get()->sendDeleted(aThis, aRes->groupName());
}
+ */
// redisplay also removed feature (used for sketch and AISObject)
ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
+ aFeature->erase();
+ // unbind after the "erase" call: on abort sketch is removes sub-objects that corrupts aFIter
+ TDF_Label aLab = aFIter.Key();
+ aFIter.Next();
+ myObjs.UnBind(aLab);
} else
aFIter.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);
myExecuteFeatures = false;
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
- if (theMarkUpdated)
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
- boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->setCheckTransactions(
- true);
+ aLoop->activateFlushes(true);
+
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ if (theMarkUpdated) {
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ boost::static_pointer_cast<Model_Session>(Model_Session::get())
+ ->setCheckTransactions(true);
myExecuteFeatures = true;
}
+TDF_Label Model_Document::resultLabel(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex)
+{
+ const boost::shared_ptr<Model_Data>& aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeatureData);
+ return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
+}
+
void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
boost::shared_ptr<ModelAPI_Result> theResult,
const int theResultIndex)
{
- boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(
- myID);
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
theResult->setDoc(aThis);
- initData(
- theResult,
- boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Father().FindChild(
- TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1),
- TAG_FEATURE_ARGUMENTS);
+ initData(theResult, resultLabel(theFeatureData, theResultIndex), TAG_FEATURE_ARGUMENTS);
if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
theResult->data()->setName(theFeatureData->name());
}
}
+static const Standard_GUID ID_CONSTRUCTION("b59fa408-8ab1-42b8-980c-af5adeebe7e4");
+static const Standard_GUID ID_BODY("c1148e9a-9b17-4e9c-9160-18e918fd0013");
+static const Standard_GUID ID_PART("1b3319b9-3e0a-4298-a1dc-3fb5aaf9be59");
+
boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
- ObjectPtr anOldObject = object(
- boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Father().FindChild(
- TAG_FEATURE_RESULTS).FindChild(theIndex + 1));
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_UAttribute::Set(aLab, ID_CONSTRUCTION);
+ ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultConstruction> aResult;
if (anOldObject) {
aResult = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anOldObject);
boost::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
- ObjectPtr anOldObject = object(
- boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Father().FindChild(
- TAG_FEATURE_RESULTS).FindChild(theIndex + 1));
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_UAttribute::Set(aLab, ID_BODY);
+ ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultBody> aResult;
if (anOldObject) {
aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(anOldObject);
boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
- ObjectPtr anOldObject = object(
- boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Father().FindChild(
- TAG_FEATURE_RESULTS).FindChild(theIndex + 1));
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_UAttribute::Set(aLab, ID_PART);
+ ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultPart> aResult;
if (anOldObject) {
aResult = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(anOldObject);
return FeaturePtr();
}
+void Model_Document::updateResults(FeaturePtr theFeature)
+{
+ // for not persistent is will be done by parametric updater automatically
+ if (!theFeature->isPersistentResult()) return;
+ // check the existing results and remove them if there is nothing on the label
+ std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
+ while(aResIter != theFeature->results().cend()) {
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(*aResIter);
+ if (aBody) {
+ if (!aBody->data()->isValid()) {
+ // found a disappeared result => remove it
+ theFeature->removeResult(aBody);
+ // start iterate from beginning because iterator is corrupted by removing
+ aResIter = theFeature->results().cbegin();
+ continue;
+ }
+ }
+ aResIter++;
+ }
+ // check that results are presented on all labels
+ int aResSize = theFeature->results().size();
+ TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father());
+ for(; aLabIter.More(); aLabIter.Next()) {
+ // here must be GUID of the feature
+ int aResIndex = aLabIter.Value().Tag() - 1;
+ ResultPtr aNewBody;
+ if (aResSize <= aResIndex) {
+ TDF_Label anArgLab = aLabIter.Value();
+ if (anArgLab.IsAttribute(ID_BODY)) {
+ aNewBody = createBody(theFeature->data(), aResIndex);
+ } else if (anArgLab.IsAttribute(ID_PART)) {
+ aNewBody = createPart(theFeature->data(), aResIndex);
+ } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION) && anArgLab.FindChild(1).HasAttribute()) {
+ Events_Error::send("Unknown type of result is found in the document");
+ }
+ if (aNewBody) {
+ theFeature->setResult(aNewBody, aResIndex);
+ }
+ }
+ }
+}
+
+void Model_Document::objectIsReferenced(const ObjectPtr& theObject)
+{
+ // only bodies are concealed now
+ ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
+ if (aResult) {
+ if (myConcealedResults.find(aResult) != myConcealedResults.end()) {
+ Events_Error::send(std::string("The object '") + aResult->data()->name() +
+ "' is already referenced");
+ } else {
+ myConcealedResults.insert(aResult);
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_ResultBody::group());
+
+ static Events_Loop* aLoop = Events_Loop::loop();
+ static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+ aECreator->sendUpdated(aResult, EVENT_DISP);
+ }
+ }
+}
+
+void Model_Document::objectIsNotReferenced(const ObjectPtr& theObject)
+{
+ // only bodies are concealed now
+ ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
+ if (aResult) {
+ std::set<ResultPtr>::iterator aFind = myConcealedResults.find(aResult);
+ if (aFind != myConcealedResults.end()) {
+ ResultPtr aFeature = *aFind;
+ myConcealedResults.erase(aFind);
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent, false);
+ } else {
+ Events_Error::send(std::string("The object '") + aResult->data()->name() +
+ "' was not referenced '");
+ }
+ }
+}
+
Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
{
return TDF_LabelMapHasher::HashCode(theLab, theUpper);