1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Document.cxx
4 // Created: 28 Feb 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_Document.h>
8 #include <Model_Data.h>
9 #include <Model_Objects.h>
10 #include <Model_Application.h>
11 #include <Model_Session.h>
12 #include <Model_Events.h>
13 #include <ModelAPI_ResultPart.h>
14 #include <ModelAPI_Validator.h>
15 #include <ModelAPI_CompositeFeature.h>
17 #include <Events_Loop.h>
18 #include <Events_Error.h>
20 #include <TDataStd_Integer.hxx>
21 #include <TDataStd_Comment.hxx>
22 #include <TDF_ChildIDIterator.hxx>
23 #include <TDataStd_ReferenceArray.hxx>
24 #include <TDataStd_HLabelArray1.hxx>
25 #include <TDataStd_Name.hxx>
26 #include <TDF_Reference.hxx>
27 #include <TDF_ChildIDIterator.hxx>
28 #include <TDF_LabelMapHasher.hxx>
29 #include <OSD_File.hxx>
30 #include <OSD_Path.hxx>
38 # define _separator_ '\\'
40 # define _separator_ '/'
43 static const int UNDO_LIMIT = 1000; // number of possible undo operations (big for sketcher)
45 static const int TAG_GENERAL = 1; // general properties tag
48 static const int TAG_CURRENT_FEATURE = 1; ///< where the reference to the current feature label is located (or no attribute if null feature)
50 Model_Document::Model_Document(const std::string theID, const std::string theKind)
51 : myID(theID), myKind(theKind),
52 myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
54 myObjs = new Model_Objects(myDoc->Main());
55 myDoc->SetUndoLimit(UNDO_LIMIT);
56 myTransactionSave = 0;
57 myExecuteFeatures = true;
58 // to have something in the document and avoid empty doc open/save problem
59 // in transaction for nesting correct working
61 TDataStd_Integer::Set(myDoc->Main().Father(), 0);
62 myDoc->CommitCommand();
65 void Model_Document::setThis(DocumentPtr theDoc)
67 myObjs->setOwner(theDoc);
70 /// Returns the file name of this document by the nameof directory and identifuer of a document
71 static TCollection_ExtendedString DocFileName(const char* theFileName, const std::string& theID)
73 TCollection_ExtendedString aPath((const Standard_CString) theFileName);
74 // remove end-separators
75 while(aPath.Length() &&
76 (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
77 aPath.Remove(aPath.Length());
79 aPath += theID.c_str();
80 aPath += ".cbf"; // standard binary file extension
84 bool Model_Document::isRoot() const
86 return this == Model_Session::get()->moduleDocument().get();
89 bool Model_Document::load(const char* theFileName, DocumentPtr theThis)
91 Handle(Model_Application) anApp = Model_Application::getApplication();
93 anApp->setLoadPath(theFileName);
95 TCollection_ExtendedString aPath(DocFileName(theFileName, myID));
96 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
98 aStatus = anApp->Open(aPath, myDoc);
99 } catch (Standard_Failure) {
100 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
102 std::string("Exception in opening of document: ") + aFail->GetMessageString());
105 bool isError = aStatus != PCDM_RS_OK;
108 case PCDM_RS_UnknownDocument:
109 Events_Error::send(std::string("Can not open document"));
111 case PCDM_RS_AlreadyRetrieved:
112 Events_Error::send(std::string("Can not open document: already opened"));
114 case PCDM_RS_AlreadyRetrievedAndModified:
116 std::string("Can not open document: already opened and modified"));
118 case PCDM_RS_NoDriver:
119 Events_Error::send(std::string("Can not open document: driver library is not found"));
121 case PCDM_RS_UnknownFileDriver:
122 Events_Error::send(std::string("Can not open document: unknown driver for opening"));
124 case PCDM_RS_OpenError:
125 Events_Error::send(std::string("Can not open document: file open error"));
127 case PCDM_RS_NoVersion:
128 Events_Error::send(std::string("Can not open document: invalid version"));
130 case PCDM_RS_NoModel:
131 Events_Error::send(std::string("Can not open document: no data model"));
133 case PCDM_RS_NoDocument:
134 Events_Error::send(std::string("Can not open document: no document inside"));
136 case PCDM_RS_FormatFailure:
137 Events_Error::send(std::string("Can not open document: format failure"));
139 case PCDM_RS_TypeNotFoundInSchema:
140 Events_Error::send(std::string("Can not open document: invalid object"));
142 case PCDM_RS_UnrecognizedFileFormat:
143 Events_Error::send(std::string("Can not open document: unrecognized file format"));
145 case PCDM_RS_MakeFailure:
146 Events_Error::send(std::string("Can not open document: make failure"));
148 case PCDM_RS_PermissionDenied:
149 Events_Error::send(std::string("Can not open document: permission denied"));
151 case PCDM_RS_DriverFailure:
152 Events_Error::send(std::string("Can not open document: driver failure"));
155 Events_Error::send(std::string("Can not open document: unknown error"));
160 myDoc->SetUndoLimit(UNDO_LIMIT);
161 // to avoid the problem that feature is created in the current, not this, document
162 std::shared_ptr<Model_Session> aSession =
163 std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
164 aSession->setActiveDocument(anApp->getDocument(myID), false);
165 aSession->setCheckTransactions(false);
168 myObjs = new Model_Objects(myDoc->Main()); // synchronisation is inside
169 myObjs->setOwner(theThis);
170 // update the current features status
171 setCurrentFeature(currentFeature(false), false);
172 aSession->setCheckTransactions(true);
173 aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false);
174 aSession->setActiveDocument(anApp->getDocument(myID), true);
179 bool Model_Document::save(const char* theFileName, std::list<std::string>& theResults)
181 // create a directory in the root document if it is not yet exist
182 Handle(Model_Application) anApp = Model_Application::getApplication();
185 CreateDirectory(theFileName, NULL);
187 mkdir(theFileName, 0x1ff);
190 // filename in the dir is id of document inside of the given directory
191 TCollection_ExtendedString aPath(DocFileName(theFileName, myID));
192 PCDM_StoreStatus aStatus;
194 aStatus = anApp->SaveAs(myDoc, aPath);
195 } catch (Standard_Failure) {
196 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
198 std::string("Exception in saving of document: ") + aFail->GetMessageString());
201 bool isDone = aStatus == PCDM_SS_OK || aStatus == PCDM_SS_No_Obj;
204 case PCDM_SS_DriverFailure:
205 Events_Error::send(std::string("Can not save document: save driver-library failure"));
207 case PCDM_SS_WriteFailure:
208 Events_Error::send(std::string("Can not save document: file writing failure"));
210 case PCDM_SS_Failure:
212 Events_Error::send(std::string("Can not save document"));
216 myTransactionSave = myTransactions.size();
217 if (isDone) { // save also sub-documents if any
218 theResults.push_back(TCollection_AsciiString(aPath).ToCString());
219 const std::set<std::string> aSubs = subDocuments(false);
220 std::set<std::string>::iterator aSubIter = aSubs.begin();
221 for (; aSubIter != aSubs.end() && isDone; aSubIter++) {
222 if (anApp->isLoadByDemand(*aSubIter)) {
223 // copy not-activated document that is not in the memory
224 std::string aDocName = *aSubIter;
225 if (!aDocName.empty()) {
227 TCollection_AsciiString aSubPath(DocFileName(anApp->loadPath().c_str(), aDocName));
228 OSD_Path aPath(aSubPath);
229 OSD_File aFile(aPath);
230 if (aFile.Exists()) {
231 TCollection_AsciiString aDestinationDir(DocFileName(theFileName, aDocName));
232 OSD_Path aDestination(aDestinationDir);
233 aFile.Copy(aDestination);
234 theResults.push_back(aDestinationDir.ToCString());
237 std::string("Can not open file ") + aSubPath.ToCString() + " for saving");
240 } else { // simply save opened document
241 isDone = subDoc(*aSubIter)->save(theFileName, theResults);
248 void Model_Document::close(const bool theForever)
250 std::shared_ptr<ModelAPI_Session> aPM = Model_Session::get();
251 if (!isRoot() && this == aPM->activeDocument().get()) {
252 aPM->setActiveDocument(aPM->moduleDocument());
253 } else if (isRoot()) {
254 // erase the active document if root is closed
255 aPM->setActiveDocument(DocumentPtr());
258 const std::set<std::string> aSubs = subDocuments(true);
259 std::set<std::string>::iterator aSubIter = aSubs.begin();
260 for (; aSubIter != aSubs.end(); aSubIter++)
261 subDoc(*aSubIter)->close(theForever);
263 // close for thid document needs no transaction in this document
264 std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(false);
266 // close all only if it is really asked, otherwise it can be undoed/redoed
270 if (myDoc->CanClose() == CDM_CCS_OK)
273 setCurrentFeature(FeaturePtr(), false); // disables all features
276 std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(true);
279 void Model_Document::startOperation()
281 if (myDoc->HasOpenCommand()) { // start of nested command
282 if (myDoc->CommitCommand()) { // commit the current: it will contain all nested after compactification
283 myTransactions.rbegin()->myOCAFNum++; // if has open command, the list is not empty
285 myNestedNum.push_back(0); // start of nested operation with zero transactions inside yet
286 myDoc->OpenCommand();
287 } else { // start the simple command
290 // starts a new operation
291 myTransactions.push_back(Transaction());
292 if (!myNestedNum.empty())
293 (*myNestedNum.rbegin())++;
295 // new command for all subs
296 const std::set<std::string> aSubs = subDocuments(true);
297 std::set<std::string>::iterator aSubIter = aSubs.begin();
298 for (; aSubIter != aSubs.end(); aSubIter++)
299 subDoc(*aSubIter)->startOperation();
302 void Model_Document::compactNested()
304 if (!myNestedNum.empty()) {
305 int aNumToCompact = *(myNestedNum.rbegin());
306 int aSumOfTransaction = 0;
307 for(int a = 0; a < aNumToCompact; a++) {
308 aSumOfTransaction += myTransactions.rbegin()->myOCAFNum;
309 myTransactions.pop_back();
311 // the latest transaction is the start of lower-level operation which startes the nested
312 myTransactions.rbegin()->myOCAFNum += aSumOfTransaction;
313 myNestedNum.pop_back();
317 bool Model_Document::finishOperation()
319 bool isNestedClosed = !myDoc->HasOpenCommand() && !myNestedNum.empty();
320 static std::shared_ptr<Model_Session> aSession =
321 std::static_pointer_cast<Model_Session>(Model_Session::get());
322 myObjs->synchronizeBackRefs();
323 Events_Loop* aLoop = Events_Loop::loop();
324 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
325 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
326 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
327 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
328 // this must be here just after everything is finished but before real transaction stop
329 // to avoid messages about modifications outside of the transaction
330 // and to rebuild everything after all updates and creates
331 if (isRoot()) { // once for root document
332 Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
333 static std::shared_ptr<Events_Message> aFinishMsg
334 (new Events_Message(Events_Loop::eventByName("FinishOperation")));
335 Events_Loop::loop()->send(aFinishMsg);
336 Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED), false);
338 // to avoid "updated" message appearance by updater
339 //aLoop->clear(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
341 // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside
342 bool aResult = false;
343 const std::set<std::string> aSubs = subDocuments(true);
344 std::set<std::string>::iterator aSubIter = aSubs.begin();
345 for (; aSubIter != aSubs.end(); aSubIter++)
346 if (subDoc(*aSubIter)->finishOperation())
349 // transaction may be empty if this document was created during this transaction (create part)
350 if (!myTransactions.empty() && myDoc->CommitCommand()) { // if commit is successfull, just increment counters
351 myTransactions.rbegin()->myOCAFNum++;
355 if (isNestedClosed) {
358 if (!aResult && !myTransactions.empty() /* it can be for just created part document */)
359 aResult = myTransactions.rbegin()->myOCAFNum != 0;
361 if (!aResult && isRoot()) {
362 // nothing inside in all documents, so remove this transaction from the transactions list
363 undoInternal(true, false);
365 // on finish clear redos in any case (issue 446) and for all subs (issue 408)
368 for (aSubIter = aSubs.begin(); aSubIter != aSubs.end(); aSubIter++) {
369 subDoc(*aSubIter)->myDoc->ClearRedos();
370 subDoc(*aSubIter)->myRedos.clear();
376 void Model_Document::abortOperation()
378 if (!myNestedNum.empty() && !myDoc->HasOpenCommand()) { // abort all what was done in nested
380 undoInternal(false, false);
383 } else { // abort the current
384 int aNumTransactions = myTransactions.rbegin()->myOCAFNum;
385 myTransactions.pop_back();
386 if (!myNestedNum.empty())
387 (*myNestedNum.rbegin())--;
388 // roll back the needed number of transactions
389 myDoc->AbortCommand();
390 for(int a = 0; a < aNumTransactions; a++)
394 // abort for all subs, flushes will be later, in the end of root abort
395 const std::set<std::string> aSubs = subDocuments(true);
396 std::set<std::string>::iterator aSubIter = aSubs.begin();
397 for (; aSubIter != aSubs.end(); aSubIter++)
398 subDoc(*aSubIter)->abortOperation();
399 // references may be changed because they are set in attributes on the fly
400 myObjs->synchronizeFeatures(true, true, isRoot());
403 bool Model_Document::isOperation() const
405 // operation is opened for all documents: no need to check subs
406 return myDoc->HasOpenCommand() == Standard_True ;
409 bool Model_Document::isModified()
411 // is modified if at least one operation was commited and not undoed
412 return myTransactions.size() != myTransactionSave || isOperation();
415 bool Model_Document::canUndo()
417 // issue 406 : if transaction is opened, but nothing to undo behind, can not undo
418 int aCurrentNum = isOperation() ? 1 : 0;
419 if (myDoc->GetAvailableUndos() > 0 &&
420 (myNestedNum.empty() || *myNestedNum.rbegin() - aCurrentNum > 0) && // there is something to undo in nested
421 myTransactions.size() - aCurrentNum > 0 /* for omitting the first useless transaction */)
423 // check other subs contains operation that can be undoed
424 const std::set<std::string> aSubs = subDocuments(true);
425 std::set<std::string>::iterator aSubIter = aSubs.begin();
426 for (; aSubIter != aSubs.end(); aSubIter++)
427 if (subDoc(*aSubIter)->canUndo())
432 void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchronize)
434 int aNumTransactions = myTransactions.rbegin()->myOCAFNum;
435 myRedos.push_back(*myTransactions.rbegin());
436 myTransactions.pop_back();
437 if (!myNestedNum.empty())
438 (*myNestedNum.rbegin())--;
439 // roll back the needed number of transactions
440 for(int a = 0; a < aNumTransactions; a++)
445 const std::set<std::string> aSubs = subDocuments(true);
446 std::set<std::string>::iterator aSubIter = aSubs.begin();
447 for (; aSubIter != aSubs.end(); aSubIter++)
448 subDoc(*aSubIter)->undoInternal(theWithSubs, theSynchronize);
450 // after redo of all sub-documents to avoid updates on not-modified data (issue 370)
451 if (theSynchronize) {
452 myObjs->synchronizeFeatures(true, true, isRoot());
453 // update the current features status
454 setCurrentFeature(currentFeature(false), false);
458 void Model_Document::undo()
460 undoInternal(true, true);
463 bool Model_Document::canRedo()
465 if (!myRedos.empty())
467 // check other subs contains operation that can be redoed
468 const std::set<std::string> aSubs = subDocuments(true);
469 std::set<std::string>::iterator aSubIter = aSubs.begin();
470 for (; aSubIter != aSubs.end(); aSubIter++)
471 if (subDoc(*aSubIter)->canRedo())
476 void Model_Document::redo()
478 if (!myNestedNum.empty())
479 (*myNestedNum.rbegin())++;
480 int aNumRedos = myRedos.rbegin()->myOCAFNum;
481 myTransactions.push_back(*myRedos.rbegin());
483 for(int a = 0; a < aNumRedos; a++)
487 const std::set<std::string> aSubs = subDocuments(true);
488 std::set<std::string>::iterator aSubIter = aSubs.begin();
489 for (; aSubIter != aSubs.end(); aSubIter++)
490 subDoc(*aSubIter)->redo();
492 // after redo of all sub-documents to avoid updates on not-modified data (issue 370)
493 myObjs->synchronizeFeatures(true, true, isRoot());
494 // update the current features status
495 setCurrentFeature(currentFeature(false), false);
498 std::list<std::string> Model_Document::undoList() const
500 std::list<std::string> aResult;
501 // the number of skipped current operations (on undo they will be aborted)
502 int aSkipCurrent = isOperation() ? 1 : 0;
503 std::list<Transaction>::const_reverse_iterator aTrIter = myTransactions.crbegin();
504 int aNumUndo = myTransactions.size();
505 if (!myNestedNum.empty())
506 aNumUndo = *myNestedNum.rbegin();
507 for( ; aNumUndo > 0; aTrIter++, aNumUndo--) {
508 if (aSkipCurrent == 0) aResult.push_back(aTrIter->myId);
514 std::list<std::string> Model_Document::redoList() const
516 std::list<std::string> aResult;
517 std::list<Transaction>::const_reverse_iterator aTrIter = myRedos.crbegin();
518 for( ; aTrIter != myRedos.crend(); aTrIter++) {
519 aResult.push_back(aTrIter->myId);
524 void Model_Document::operationId(const std::string& theId)
526 myTransactions.rbegin()->myId = theId;
529 FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurrent)
531 std::shared_ptr<Model_Session> aSession =
532 std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get());
533 FeaturePtr aFeature = aSession->createFeature(theID, this);
536 Model_Document* aDocToAdd;
537 if (!aFeature->documentToAdd().empty()) { // use the customized document to add
538 if (aFeature->documentToAdd() != kind()) { // the root document by default
539 aDocToAdd = std::dynamic_pointer_cast<Model_Document>(aSession->moduleDocument()).get();
543 } else { // if customized is not presented, add to "this" document
547 aDocToAdd->myObjs->addFeature(aFeature, currentFeature(false));
548 if (!aFeature->isAction()) { // do not add action to the data model
549 if (theMakeCurrent) // after all this feature stays in the document, so make it current
550 setCurrentFeature(aFeature, false);
551 } else { // feature must be executed
552 // no creation event => updater not working, problem with remove part
560 void Model_Document::refsToFeature(FeaturePtr theFeature,
561 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs, const bool isSendError)
563 myObjs->refsToFeature(theFeature, theRefs, isSendError);
566 void Model_Document::removeFeature(FeaturePtr theFeature)
568 // if this feature is current, make the current the previous feature
569 if (theFeature == currentFeature(false)) {
570 FeaturePtr aPrev = myObjs->nextFeature(theFeature, true);
571 setCurrentFeature(aPrev, false);
573 myObjs->removeFeature(theFeature);
576 void Model_Document::updateHistory(const std::shared_ptr<ModelAPI_Object> theObject)
578 myObjs->updateHistory(theObject);
581 void Model_Document::updateHistory(const std::string theGroup)
583 myObjs->updateHistory(theGroup);
586 std::shared_ptr<ModelAPI_Document> Model_Document::subDocument(std::string theDocID)
588 return Model_Application::getApplication()->getDocument(theDocID);
591 const std::set<std::string> Model_Document::subDocuments(const bool theActivatedOnly) const
593 std::set<std::string> aResult;
594 std::list<ResultPtr> aPartResults;
595 myObjs->allResults(ModelAPI_ResultPart::group(), aPartResults);
596 std::list<ResultPtr>::iterator aPartRes = aPartResults.begin();
597 for(; aPartRes != aPartResults.end(); aPartRes++) {
598 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aPartRes);
599 if (aPart && (!theActivatedOnly || aPart->isActivated()))
600 aResult.insert(aPart->data()->name());
605 std::shared_ptr<Model_Document> Model_Document::subDoc(std::string theDocID)
607 // just store sub-document identifier here to manage it later
608 return std::dynamic_pointer_cast<Model_Document>(
609 Model_Application::getApplication()->getDocument(theDocID));
612 ObjectPtr Model_Document::object(const std::string& theGroupID, const int theIndex)
614 return myObjs->object(theGroupID, theIndex);
617 std::shared_ptr<ModelAPI_Object> Model_Document::objectByName(
618 const std::string& theGroupID, const std::string& theName)
620 return myObjs->objectByName(theGroupID, theName);
623 const int Model_Document::index(std::shared_ptr<ModelAPI_Object> theObject)
625 return myObjs->index(theObject);
628 int Model_Document::size(const std::string& theGroupID)
630 return myObjs->size(theGroupID);
633 std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theVisible)
635 TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
636 Handle(TDF_Reference) aRef;
637 if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
638 TDF_Label aLab = aRef->Get();
639 FeaturePtr aResult = myObjs->feature(aLab);
640 if (theVisible) { // get nearest visible (in history) going up
641 while(aResult.get() && !aResult->isInHistory()) {
642 aResult = myObjs->nextFeature(aResult, true);
647 return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
650 void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
651 const bool theVisible)
653 TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
654 CompositeFeaturePtr aMain; // main feature that may nest the new current
655 if (theCurrent.get()) {
657 if (theVisible) { // make features below which are not in history also enabled: sketch subs
658 FeaturePtr aNext = myObjs->nextFeature(theCurrent);
659 for (; aNext.get(); aNext = myObjs->nextFeature(theCurrent)) {
660 if (aNext->isInHistory()) {
661 break; // next in history is not needed
662 } else { // next not in history is good for making current
667 aMain = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theCurrent);
669 // if feature nests into compisite feature, make the composite feature as current
670 const std::set<AttributePtr>& aRefsToMe = theCurrent->data()->refsToMe();
671 std::set<AttributePtr>::const_iterator aRefToMe = aRefsToMe.begin();
672 for(; aRefToMe != aRefsToMe.end(); aRefToMe++) {
673 CompositeFeaturePtr aComposite =
674 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*aRefToMe)->owner());
675 if (aComposite.get() && aComposite->isSub(theCurrent)) {
682 std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
683 if (!aData.get()) return; // unknown case
684 TDF_Label aFeatureLabel = aData->label().Father();
686 Handle(TDF_Reference) aRef;
687 if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
688 aRef->Set(aFeatureLabel);
690 aRef = TDF_Reference::Set(aRefLab, aFeatureLabel);
692 } else { // remove reference for the null feature
693 aRefLab.ForgetAttribute(TDF_Reference::GetID());
695 // make all features after this feature disabled in reversed order (to remove results without deps)
696 static Events_Loop* aLoop = Events_Loop::loop();
697 static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
699 bool aPassed = false; // flag that the current object is already passed in cycle
700 FeaturePtr anIter = myObjs->lastFeature();
701 for(; anIter.get(); anIter = myObjs->nextFeature(anIter, true)) {
702 // check this before passed become enabled: the current feature is enabled!
703 if (anIter == theCurrent) aPassed = true;
705 bool aDisabledFlag = !aPassed;
706 if (aMain.get() && aMain->isSub(anIter))
707 aDisabledFlag = false;
708 if (anIter->setDisabled(aDisabledFlag)) {
709 // state of feature is changed => so feature become updated
710 static Events_ID anUpdateEvent = aLoop->eventByName(EVENT_OBJECT_UPDATED);
711 ModelAPI_EventCreator::get()->sendUpdated(anIter, anUpdateEvent);
712 // flush is in the end of this method
713 ModelAPI_EventCreator::get()->sendUpdated(anIter, aRedispEvent /*, false*/);
716 aLoop->flush(aRedispEvent);
719 TDF_Label Model_Document::generalLabel() const
721 return myDoc->Main().FindChild(TAG_GENERAL);
724 std::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
725 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
727 return myObjs->createConstruction(theFeatureData, theIndex);
730 std::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
731 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
733 return myObjs->createBody(theFeatureData, theIndex);
736 std::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
737 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
739 return myObjs->createPart(theFeatureData, theIndex);
742 std::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
743 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
745 return myObjs->createGroup(theFeatureData, theIndex);
748 std::shared_ptr<ModelAPI_ResultParameter> Model_Document::createParameter(
749 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
751 return myObjs->createParameter(theFeatureData, theIndex);
754 std::shared_ptr<ModelAPI_Feature> Model_Document::feature(
755 const std::shared_ptr<ModelAPI_Result>& theResult)
757 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theResult->data());
759 TDF_Label aFeatureLab = aData->label().Father().Father().Father();
760 return myObjs->feature(aFeatureLab);
765 Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
767 return TDF_LabelMapHasher::HashCode(theLab, theUpper);
770 Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2)
772 return TDF_LabelMapHasher::IsEqual(theLab1, theLab2);
775 void Model_Document::addNamingName(const TDF_Label theLabel, std::string theName)
777 myNamingNames[theName] = theLabel;
780 TDF_Label Model_Document::findNamingName(std::string theName)
782 std::map<std::string, TDF_Label>::iterator aFind = myNamingNames.find(theName);
783 if (aFind == myNamingNames.end())
784 return TDF_Label(); // not found
785 return aFind->second;
788 ResultPtr Model_Document::findByName(const std::string theName)
790 return myObjs->findByName(theName);