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_Application.h>
10 #include <Model_Session.h>
11 #include <Model_Events.h>
12 #include <Model_ResultPart.h>
13 #include <Model_ResultConstruction.h>
14 #include <Model_ResultBody.h>
15 #include <Model_ResultGroup.h>
16 #include <ModelAPI_Validator.h>
17 #include <ModelAPI_CompositeFeature.h>
18 #include <Events_Loop.h>
19 #include <Events_Error.h>
21 #include <TDataStd_Integer.hxx>
22 #include <TDataStd_Comment.hxx>
23 #include <TDF_ChildIDIterator.hxx>
24 #include <TDataStd_ReferenceArray.hxx>
25 #include <TDataStd_HLabelArray1.hxx>
26 #include <TDataStd_Name.hxx>
27 #include <TDF_Reference.hxx>
28 #include <TDF_ChildIDIterator.hxx>
29 #include <TDF_LabelMapHasher.hxx>
30 #include <OSD_File.hxx>
31 #include <OSD_Path.hxx>
39 # define _separator_ '\\'
41 # define _separator_ '/'
44 static const int UNDO_LIMIT = 1000; // number of possible undo operations (big for sketcher)
46 static const int TAG_GENERAL = 1; // general properties tag
47 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (features, results)
48 static const int TAG_HISTORY = 3; // tag of the history sub-tree (python dump)
51 static const int TAG_FEATURE_ARGUMENTS = 1; ///< where the arguments are located
52 static const int TAG_FEATURE_RESULTS = 2; ///< where the results are located
55 /// 0:1:2 - where features are located
56 /// 0:1:2:N:1 - data of the feature N
57 /// 0:1:2:N:2:K:1 - data of the K result of the feature N
59 Model_Document::Model_Document(const std::string theID, const std::string theKind)
60 : myID(theID), myKind(theKind),
61 myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
63 myDoc->SetUndoLimit(UNDO_LIMIT);
64 myTransactionSave = 0;
65 myExecuteFeatures = true;
66 // to have something in the document and avoid empty doc open/save problem
67 // in transaction for nesting correct working
69 TDataStd_Integer::Set(myDoc->Main().Father(), 0);
70 myDoc->CommitCommand();
73 /// Returns the file name of this document by the nameof directory and identifuer of a document
74 static TCollection_ExtendedString DocFileName(const char* theFileName, const std::string& theID)
76 TCollection_ExtendedString aPath((const Standard_CString) theFileName);
77 // remove end-separators
78 while(aPath.Length() && (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
79 aPath.Remove(aPath.Length());
81 aPath += theID.c_str();
82 aPath += ".cbf"; // standard binary file extension
86 bool Model_Document::load(const char* theFileName)
88 Handle(Model_Application) anApp = Model_Application::getApplication();
89 if (this == Model_Session::get()->moduleDocument().get()) {
90 anApp->setLoadPath(theFileName);
92 TCollection_ExtendedString aPath(DocFileName(theFileName, myID));
93 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
95 aStatus = anApp->Open(aPath, myDoc);
96 } catch (Standard_Failure) {
97 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
99 std::string("Exception in opening of document: ") + aFail->GetMessageString());
102 bool isError = aStatus != PCDM_RS_OK;
105 case PCDM_RS_UnknownDocument:
106 Events_Error::send(std::string("Can not open document"));
108 case PCDM_RS_AlreadyRetrieved:
109 Events_Error::send(std::string("Can not open document: already opened"));
111 case PCDM_RS_AlreadyRetrievedAndModified:
113 std::string("Can not open document: already opened and modified"));
115 case PCDM_RS_NoDriver:
116 Events_Error::send(std::string("Can not open document: driver library is not found"));
118 case PCDM_RS_UnknownFileDriver:
119 Events_Error::send(std::string("Can not open document: unknown driver for opening"));
121 case PCDM_RS_OpenError:
122 Events_Error::send(std::string("Can not open document: file open error"));
124 case PCDM_RS_NoVersion:
125 Events_Error::send(std::string("Can not open document: invalid version"));
127 case PCDM_RS_NoModel:
128 Events_Error::send(std::string("Can not open document: no data model"));
130 case PCDM_RS_NoDocument:
131 Events_Error::send(std::string("Can not open document: no document inside"));
133 case PCDM_RS_FormatFailure:
134 Events_Error::send(std::string("Can not open document: format failure"));
136 case PCDM_RS_TypeNotFoundInSchema:
137 Events_Error::send(std::string("Can not open document: invalid object"));
139 case PCDM_RS_UnrecognizedFileFormat:
140 Events_Error::send(std::string("Can not open document: unrecognized file format"));
142 case PCDM_RS_MakeFailure:
143 Events_Error::send(std::string("Can not open document: make failure"));
145 case PCDM_RS_PermissionDenied:
146 Events_Error::send(std::string("Can not open document: permission denied"));
148 case PCDM_RS_DriverFailure:
149 Events_Error::send(std::string("Can not open document: driver failure"));
152 Events_Error::send(std::string("Can not open document: unknown error"));
157 myDoc->SetUndoLimit(UNDO_LIMIT);
158 // to avoid the problem that feature is created in the current, not this, document
159 std::shared_ptr<Model_Session> aSession =
160 std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
161 aSession->setActiveDocument(anApp->getDocument(myID), false);
162 aSession->setCheckTransactions(false);
163 synchronizeFeatures(false, true);
164 aSession->setCheckTransactions(true);
165 aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false);
166 aSession->setActiveDocument(anApp->getDocument(myID), true);
171 bool Model_Document::save(const char* theFileName, std::list<std::string>& theResults)
173 // create a directory in the root document if it is not yet exist
174 Handle(Model_Application) anApp = Model_Application::getApplication();
175 if (this == Model_Session::get()->moduleDocument().get()) {
177 CreateDirectory(theFileName, NULL);
179 mkdir(theFileName, 0x1ff);
182 // filename in the dir is id of document inside of the given directory
183 TCollection_ExtendedString aPath(DocFileName(theFileName, myID));
184 PCDM_StoreStatus aStatus;
186 aStatus = anApp->SaveAs(myDoc, aPath);
187 } catch (Standard_Failure) {
188 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
190 std::string("Exception in saving of document: ") + aFail->GetMessageString());
193 bool isDone = aStatus == PCDM_SS_OK || aStatus == PCDM_SS_No_Obj;
196 case PCDM_SS_DriverFailure:
197 Events_Error::send(std::string("Can not save document: save driver-library failure"));
199 case PCDM_SS_WriteFailure:
200 Events_Error::send(std::string("Can not save document: file writing failure"));
202 case PCDM_SS_Failure:
204 Events_Error::send(std::string("Can not save document"));
208 myTransactionSave = myTransactions.size();
209 if (isDone) { // save also sub-documents if any
210 theResults.push_back(TCollection_AsciiString(aPath).ToCString());
211 const std::set<std::string> aSubs = subDocuments(false);
212 std::set<std::string>::iterator aSubIter = aSubs.begin();
213 for (; aSubIter != aSubs.end() && isDone; aSubIter++) {
214 if (anApp->isLoadByDemand(*aSubIter)) {
215 // copy not-activated document that is not in the memory
216 std::string aDocName = *aSubIter;
217 if (!aDocName.empty()) {
219 TCollection_AsciiString aSubPath(DocFileName(anApp->loadPath().c_str(), aDocName));
220 OSD_Path aPath(aSubPath);
221 OSD_File aFile(aPath);
222 if (aFile.Exists()) {
223 TCollection_AsciiString aDestinationDir(DocFileName(theFileName, aDocName));
224 OSD_Path aDestination(aDestinationDir);
225 aFile.Copy(aDestination);
226 theResults.push_back(aDestinationDir.ToCString());
229 std::string("Can not open file ") + aSubPath.ToCString() + " for saving");
232 } else { // simply save opened document
233 isDone = subDoc(*aSubIter)->save(theFileName, theResults);
240 void Model_Document::close(const bool theForever)
242 std::shared_ptr<ModelAPI_Session> aPM = Model_Session::get();
243 if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) {
244 aPM->setActiveDocument(aPM->moduleDocument());
245 } else if (this == aPM->moduleDocument().get()) {
246 // erase the active document if root is closed
247 aPM->setActiveDocument(DocumentPtr());
250 const std::set<std::string> aSubs = subDocuments(true);
251 std::set<std::string>::iterator aSubIter = aSubs.begin();
252 for (; aSubIter != aSubs.end(); aSubIter++)
253 subDoc(*aSubIter)->close(theForever);
255 // close for thid document needs no transaction in this document
256 std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(false);
258 // delete all features of this document
259 std::shared_ptr<ModelAPI_Document> aThis =
260 Model_Application::getApplication()->getDocument(myID);
261 Events_Loop* aLoop = Events_Loop::loop();
262 NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeaturesIter(myObjs);
263 for(; aFeaturesIter.More(); aFeaturesIter.Next()) {
264 FeaturePtr aFeature = aFeaturesIter.Value();
265 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
266 ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Feature::group());
267 ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
268 aFeature->eraseResults();
269 if (theForever) { // issue #294: do not delete content of the document until it can be redone
272 aFeature->data()->execState(ModelAPI_StateMustBeUpdated);
278 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
279 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
281 // close all only if it is really asked, otherwise it can be undoed/redoed
283 if (myDoc->CanClose() == CDM_CCS_OK)
287 std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(true);
290 void Model_Document::startOperation()
292 if (myDoc->HasOpenCommand()) { // start of nested command
293 if (myDoc->CommitCommand()) { // commit the current: it will contain all nested after compactification
294 myTransactions.rbegin()->myOCAFNum++; // if has open command, the list is not empty
296 myNestedNum.push_back(0); // start of nested operation with zero transactions inside yet
297 myDoc->OpenCommand();
298 } else { // start the simple command
301 // starts a new operation
302 myTransactions.push_back(Transaction());
303 if (!myNestedNum.empty())
304 (*myNestedNum.rbegin())++;
306 // new command for all subs
307 const std::set<std::string> aSubs = subDocuments(true);
308 std::set<std::string>::iterator aSubIter = aSubs.begin();
309 for (; aSubIter != aSubs.end(); aSubIter++)
310 subDoc(*aSubIter)->startOperation();
313 void Model_Document::compactNested()
315 if (!myNestedNum.empty()) {
316 int aNumToCompact = *(myNestedNum.rbegin());
317 int aSumOfTransaction = 0;
318 for(int a = 0; a < aNumToCompact; a++) {
319 aSumOfTransaction += myTransactions.rbegin()->myOCAFNum;
320 myTransactions.pop_back();
322 // the latest transaction is the start of lower-level operation which startes the nested
323 myTransactions.rbegin()->myOCAFNum += aSumOfTransaction;
324 myNestedNum.pop_back();
328 bool Model_Document::finishOperation()
330 bool isNestedClosed = !myDoc->HasOpenCommand() && !myNestedNum.empty();
331 static std::shared_ptr<Model_Session> aSession =
332 std::static_pointer_cast<Model_Session>(Model_Session::get());
333 synchronizeBackRefs();
334 Events_Loop* aLoop = Events_Loop::loop();
335 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
336 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
337 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
338 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
339 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
340 // this must be here just after everything is finished but before real transaction stop
341 // to avoid messages about modifications outside of the transaction
342 // and to rebuild everything after all updates and creates
343 if (Model_Session::get()->moduleDocument().get() == this) { // once for root document
344 Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
345 static std::shared_ptr<Events_Message> aFinishMsg
346 (new Events_Message(Events_Loop::eventByName("FinishOperation")));
347 Events_Loop::loop()->send(aFinishMsg);
348 Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED), false);
350 // to avoid "updated" message appearance by updater
351 //aLoop->clear(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
353 // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside
354 bool aResult = false;
355 const std::set<std::string> aSubs = subDocuments(true);
356 std::set<std::string>::iterator aSubIter = aSubs.begin();
357 for (; aSubIter != aSubs.end(); aSubIter++)
358 if (subDoc(*aSubIter)->finishOperation())
361 // transaction may be empty if this document was created during this transaction (create part)
362 if (!myTransactions.empty() && myDoc->CommitCommand()) { // if commit is successfull, just increment counters
363 myTransactions.rbegin()->myOCAFNum++;
367 if (isNestedClosed) {
370 if (!aResult && !myTransactions.empty() /* it can be for just created part document */)
371 aResult = myTransactions.rbegin()->myOCAFNum != 0;
373 if (!aResult && Model_Session::get()->moduleDocument().get() == this) {
374 // nothing inside in all documents, so remove this transaction from the transactions list
375 undoInternal(true, false);
382 void Model_Document::abortOperation()
384 if (!myNestedNum.empty() && !myDoc->HasOpenCommand()) { // abort all what was done in nested
386 undoInternal(false, false);
389 } else { // abort the current
390 int aNumTransactions = myTransactions.rbegin()->myOCAFNum;
391 myTransactions.pop_back();
392 if (!myNestedNum.empty())
393 (*myNestedNum.rbegin())--;
394 // roll back the needed number of transactions
395 myDoc->AbortCommand();
396 for(int a = 0; a < aNumTransactions; a++)
400 synchronizeFeatures(true, false); // references were not changed since transaction start
401 // abort for all subs
402 const std::set<std::string> aSubs = subDocuments(true);
403 std::set<std::string>::iterator aSubIter = aSubs.begin();
404 for (; aSubIter != aSubs.end(); aSubIter++)
405 subDoc(*aSubIter)->abortOperation();
408 bool Model_Document::isOperation() const
410 // operation is opened for all documents: no need to check subs
411 return myDoc->HasOpenCommand() == Standard_True ;
414 bool Model_Document::isModified()
416 // is modified if at least one operation was commited and not undoed
417 return myTransactions.size() != myTransactionSave || isOperation();
420 bool Model_Document::canUndo()
422 // issue 406 : if transaction is opened, but nothing to undo behind, can not undo
423 int aCurrentNum = isOperation() ? 1 : 0;
424 if (myDoc->GetAvailableUndos() > 0 &&
425 (myNestedNum.empty() || *myNestedNum.rbegin() - aCurrentNum > 0) && // there is something to undo in nested
426 myTransactions.size() - aCurrentNum > 0 /* for omitting the first useless transaction */)
428 // check other subs contains operation that can be undoed
429 const std::set<std::string> aSubs = subDocuments(true);
430 std::set<std::string>::iterator aSubIter = aSubs.begin();
431 for (; aSubIter != aSubs.end(); aSubIter++)
432 if (subDoc(*aSubIter)->canUndo())
437 void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchronize)
439 int aNumTransactions = myTransactions.rbegin()->myOCAFNum;
440 myRedos.push_back(*myTransactions.rbegin());
441 myTransactions.pop_back();
442 if (!myNestedNum.empty())
443 (*myNestedNum.rbegin())--;
444 // roll back the needed number of transactions
445 for(int a = 0; a < aNumTransactions; a++)
449 synchronizeFeatures(true, true);
452 const std::set<std::string> aSubs = subDocuments(true);
453 std::set<std::string>::iterator aSubIter = aSubs.begin();
454 for (; aSubIter != aSubs.end(); aSubIter++)
455 subDoc(*aSubIter)->undoInternal(theWithSubs, theSynchronize);
459 void Model_Document::undo()
461 undoInternal(true, true);
464 bool Model_Document::canRedo()
466 if (!myRedos.empty())
468 // check other subs contains operation that can be redoed
469 const std::set<std::string> aSubs = subDocuments(true);
470 std::set<std::string>::iterator aSubIter = aSubs.begin();
471 for (; aSubIter != aSubs.end(); aSubIter++)
472 if (subDoc(*aSubIter)->canRedo())
477 void Model_Document::redo()
479 if (!myNestedNum.empty())
480 (*myNestedNum.rbegin())++;
481 int aNumRedos = myRedos.rbegin()->myOCAFNum;
482 myTransactions.push_back(*myRedos.rbegin());
484 for(int a = 0; a < aNumRedos; a++)
487 synchronizeFeatures(true, true);
489 const std::set<std::string> aSubs = subDocuments(true);
490 std::set<std::string>::iterator aSubIter = aSubs.begin();
491 for (; aSubIter != aSubs.end(); aSubIter++)
492 subDoc(*aSubIter)->redo();
495 std::list<std::string> Model_Document::undoList() const
497 std::list<std::string> aResult;
498 // the number of skipped current operations (on undo they will be aborted)
499 int aSkipCurrent = isOperation() ? 1 : 0;
500 std::list<Transaction>::const_reverse_iterator aTrIter = myTransactions.crbegin();
501 int aNumUndo = myTransactions.size();
502 if (!myNestedNum.empty())
503 aNumUndo = *myNestedNum.rbegin();
504 for( ; aNumUndo > 0; aTrIter++, aNumUndo--) {
505 if (aSkipCurrent == 0) aResult.push_back(aTrIter->myId);
511 std::list<std::string> Model_Document::redoList() const
513 std::list<std::string> aResult;
514 std::list<Transaction>::const_reverse_iterator aTrIter = myRedos.crbegin();
515 for( ; aTrIter != myRedos.crend(); aTrIter++) {
516 aResult.push_back(aTrIter->myId);
521 void Model_Document::operationId(const std::string& theId)
523 myTransactions.rbegin()->myId = theId;
526 /// Append to the array of references a new referenced label
527 static void AddToRefArray(TDF_Label& theArrayLab, TDF_Label& theReferenced)
529 Handle(TDataStd_ReferenceArray) aRefs;
530 if (!theArrayLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
531 aRefs = TDataStd_ReferenceArray::Set(theArrayLab, 0, 0);
532 aRefs->SetValue(0, theReferenced);
533 } else { // extend array by one more element
534 Handle(TDataStd_HLabelArray1) aNewArray = new TDataStd_HLabelArray1(aRefs->Lower(),
536 for (int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
537 aNewArray->SetValue(a, aRefs->Value(a));
539 aNewArray->SetValue(aRefs->Upper() + 1, theReferenced);
540 aRefs->SetInternalArray(aNewArray);
544 FeaturePtr Model_Document::addFeature(std::string theID)
546 TDF_Label anEmptyLab;
547 FeaturePtr anEmptyFeature;
548 FeaturePtr aFeature = ModelAPI_Session::get()->createFeature(theID);
551 Model_Document* aDocToAdd;
552 if (aFeature->documentToAdd().get()) { // use the customized document to add
553 aDocToAdd = std::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd()).get();
554 } else { // if customized is not presented, add to "this" document
558 TDF_Label aFeatureLab;
559 if (!aFeature->isAction()) { // do not add action to the data model
560 TDF_Label aFeaturesLab = aDocToAdd->featuresLabel();
561 aFeatureLab = aFeaturesLab.NewChild();
562 aDocToAdd->initData(aFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS);
563 // keep the feature ID to restore document later correctly
564 TDataStd_Comment::Set(aFeatureLab, aFeature->getKind().c_str());
565 aDocToAdd->myObjs.Bind(aFeatureLab, aFeature);
566 // store feature in the history of features array
567 if (aFeature->isInHistory()) {
568 AddToRefArray(aFeaturesLab, aFeatureLab);
571 if (!aFeature->isAction()) { // do not add action to the data model
572 // event: feature is added
573 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
574 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
575 } else { // feature must be executed
576 // no creation event => updater not working, problem with remove part
583 /// Appenad to the array of references a new referenced label.
584 /// If theIndex is not -1, removes element at this index, not theReferenced.
585 /// \returns the index of removed element
586 static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, const int theIndex =
589 int aResult = -1; // no returned
590 Handle(TDataStd_ReferenceArray) aRefs;
591 if (theArrayLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
592 if (aRefs->Length() == 1) { // just erase an array
593 if ((theIndex == -1 && aRefs->Value(0) == theReferenced) || theIndex == 0) {
594 theArrayLab.ForgetAttribute(TDataStd_ReferenceArray::GetID());
597 } else { // reduce the array
598 Handle(TDataStd_HLabelArray1) aNewArray = new TDataStd_HLabelArray1(aRefs->Lower(),
600 int aCount = aRefs->Lower();
601 for (int a = aCount; a <= aRefs->Upper(); a++, aCount++) {
602 if ((theIndex == -1 && aRefs->Value(a) == theReferenced) || theIndex == a) {
606 aNewArray->SetValue(aCount, aRefs->Value(a));
609 aRefs->SetInternalArray(aNewArray);
615 void Model_Document::refsToFeature(FeaturePtr theFeature,
616 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
617 const bool isSendError)
619 // check the feature: it must have no depended objects on it
620 // the dependencies can be in the feature results
621 std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
622 for(; aResIter != theFeature->results().cend(); aResIter++) {
623 ResultPtr aResult = (*aResIter);
624 std::shared_ptr<Model_Data> aData =
625 std::dynamic_pointer_cast<Model_Data>(aResult->data());
626 if (aData.get() != NULL) {
627 const std::set<AttributePtr>& aRefs = aData->refsToMe();
628 std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end();
629 for(; aRefIt != aRefLast; aRefIt++) {
630 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
631 if (aFeature.get() != NULL)
632 theRefs.insert(aFeature);
636 // the dependencies can be in the feature itself
637 std::shared_ptr<Model_Data> aData =
638 std::dynamic_pointer_cast<Model_Data>(theFeature->data());
639 if (aData && !aData->refsToMe().empty()) {
640 const std::set<AttributePtr>& aRefs = aData->refsToMe();
641 std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end();
642 for(; aRefIt != aRefLast; aRefIt++) {
643 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
644 if (aFeature.get() != NULL)
645 theRefs.insert(aFeature);
649 if (!theRefs.empty() && isSendError) {
651 "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
655 void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck*/)
657 std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theFeature->data());
659 TDF_Label aFeatureLabel = aData->label().Father();
660 if (myObjs.IsBound(aFeatureLabel))
661 myObjs.UnBind(aFeatureLabel);
663 return; // not found feature => do not remove
665 // checking that the sub-element of composite feature is removed: if yes, inform the owner
666 std::set<std::shared_ptr<ModelAPI_Feature> > aRefs;
667 refsToFeature(theFeature, aRefs, false);
668 std::set<std::shared_ptr<ModelAPI_Feature> >::iterator aRefIter = aRefs.begin();
669 for(; aRefIter != aRefs.end(); aRefIter++) {
670 std::shared_ptr<ModelAPI_CompositeFeature> aComposite =
671 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aRefIter);
672 if (aComposite.get()) {
673 aComposite->removeFeature(theFeature);
679 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
680 ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
681 // erase all attributes under the label of feature
682 aFeatureLabel.ForgetAllAttributes();
683 // remove it from the references array
684 if (theFeature->isInHistory()) {
685 RemoveFromRefArray(featuresLabel(), aFeatureLabel);
687 // event: feature is deleted
688 ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
692 void Model_Document::addToHistory(const std::shared_ptr<ModelAPI_Object> theObject)
694 TDF_Label aFeaturesLab = featuresLabel();
695 std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theObject->data());
697 return; // not found feature => do not remove
699 TDF_Label aFeatureLabel = aData->label().Father();
700 // store feature in the history of features array
701 if (theObject->isInHistory()) {
702 AddToRefArray(aFeaturesLab, aFeatureLabel);
704 RemoveFromRefArray(aFeaturesLab, aFeatureLabel);
708 FeaturePtr Model_Document::feature(TDF_Label& theLabel) const
710 if (myObjs.IsBound(theLabel))
711 return myObjs.Find(theLabel);
712 return FeaturePtr(); // not found
715 ObjectPtr Model_Document::object(TDF_Label theLabel)
717 // try feature by label
718 FeaturePtr aFeature = feature(theLabel);
720 return feature(theLabel);
721 TDF_Label aFeatureLabel = theLabel.Father().Father(); // let's suppose it is result
722 aFeature = feature(aFeatureLabel);
724 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
725 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
726 for (; aRIter != aResults.cend(); aRIter++) {
727 std::shared_ptr<Model_Data> aResData = std::dynamic_pointer_cast<Model_Data>(
729 if (aResData->label().Father().IsEqual(theLabel))
733 return FeaturePtr(); // not found
736 std::shared_ptr<ModelAPI_Document> Model_Document::subDocument(std::string theDocID)
738 return Model_Application::getApplication()->getDocument(theDocID);
741 const std::set<std::string> Model_Document::subDocuments(const bool theActivatedOnly) const
743 std::set<std::string> aResult;
744 // comment must be in any feature: it is kind
746 TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
747 for (; aLabIter.More(); aLabIter.Next()) {
748 TDF_Label aFLabel = aLabIter.Value()->Label();
749 FeaturePtr aFeature = feature(aFLabel);
750 if (aFeature.get()) { // if document is closed the feature may be not in myObjs map
751 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
752 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
753 for (; aRIter != aResults.cend(); aRIter++) {
754 if ((*aRIter)->groupName() != ModelAPI_ResultPart::group()) continue;
755 if ((*aRIter)->isInHistory()) {
756 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRIter);
757 if (aPart && (!theActivatedOnly || aPart->isActivated()))
758 aResult.insert(aPart->data()->name());
766 std::shared_ptr<Model_Document> Model_Document::subDoc(std::string theDocID)
768 // just store sub-document identifier here to manage it later
769 return std::dynamic_pointer_cast<Model_Document>(
770 Model_Application::getApplication()->getDocument(theDocID));
773 ObjectPtr Model_Document::object(const std::string& theGroupID, const int theIndex,
774 const bool theHidden)
776 if (theGroupID == ModelAPI_Feature::group()) {
779 TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
780 for (; aLabIter.More(); aLabIter.Next()) {
781 if (theIndex == anIndex) {
782 TDF_Label aFLabel = aLabIter.Value()->Label();
783 return feature(aFLabel);
788 Handle(TDataStd_ReferenceArray) aRefs;
789 if (!featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
791 if (aRefs->Lower() > theIndex || aRefs->Upper() < theIndex)
793 TDF_Label aFeatureLabel = aRefs->Value(theIndex);
794 return feature(aFeatureLabel);
797 // comment must be in any feature: it is kind
799 TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
800 for (; aLabIter.More(); aLabIter.Next()) {
801 TDF_Label aFLabel = aLabIter.Value()->Label();
802 FeaturePtr aFeature = feature(aFLabel);
803 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
804 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
805 for (; aRIter != aResults.cend(); aRIter++) {
806 if ((*aRIter)->groupName() != theGroupID) continue;
807 bool isIn = theHidden && (*aRIter)->isInHistory();
808 if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
809 isIn = !(*aRIter)->isConcealed();
812 if (anIndex == theIndex)
823 int Model_Document::size(const std::string& theGroupID, const bool theHidden)
826 if (theGroupID == ModelAPI_Feature::group()) {
828 return myObjs.Size();
830 Handle(TDataStd_ReferenceArray) aRefs;
831 if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
832 return aRefs->Length();
835 // comment must be in any feature: it is kind
836 TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
837 for (; aLabIter.More(); aLabIter.Next()) {
838 TDF_Label aFLabel = aLabIter.Value()->Label();
839 FeaturePtr aFeature = feature(aFLabel);
840 if (!aFeature) // may be on close
842 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
843 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
844 for (; aRIter != aResults.cend(); aRIter++) {
845 if ((*aRIter)->groupName() != theGroupID) continue;
846 bool isIn = theHidden;
847 if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
848 isIn = !(*aRIter)->isConcealed();
855 // group is not found
859 TDF_Label Model_Document::featuresLabel() const
861 return myDoc->Main().FindChild(TAG_OBJECTS);
864 void Model_Document::setUniqueName(FeaturePtr theFeature)
866 if (!theFeature->data()->name().empty())
867 return; // not needed, name is already defined
868 std::string aName; // result
869 // first count all objects of such kind to start with index = count + 1
871 NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myObjs);
872 for (; aFIter.More(); aFIter.Next()) {
873 if (aFIter.Value()->getKind() == theFeature->getKind())
876 // generate candidate name
877 std::stringstream aNameStream;
878 aNameStream << theFeature->getKind() << "_" << aNumObjects + 1;
879 aName = aNameStream.str();
880 // check this is unique, if not, increase index by 1
881 for (aFIter.Initialize(myObjs); aFIter.More();) {
882 FeaturePtr aFeature = aFIter.Value();
883 bool isSameName = aFeature->data()->name() == aName;
884 if (!isSameName) { // check also results to avoid same results names (actual for Parts)
885 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
886 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
887 for (; aRIter != aResults.cend(); aRIter++) {
888 isSameName = (*aRIter)->data()->name() == aName;
893 std::stringstream aNameStream;
894 aNameStream << theFeature->getKind() << "_" << aNumObjects + 1;
895 aName = aNameStream.str();
896 // reinitialize iterator to make sure a new name is unique
897 aFIter.Initialize(myObjs);
901 theFeature->data()->setName(aName);
904 void Model_Document::initData(ObjectPtr theObj, TDF_Label theLab, const int theTag)
906 std::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(
908 std::shared_ptr<Model_Data> aData(new Model_Data);
909 aData->setLabel(theLab.FindChild(theTag));
910 aData->setObject(theObj);
911 theObj->setDoc(aThis);
912 theObj->setData(aData);
913 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
915 setUniqueName(aFeature); // must be before "initAttributes" because duplicate part uses name
917 theObj->initAttributes();
920 void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
922 std::shared_ptr<ModelAPI_Document> aThis =
923 Model_Application::getApplication()->getDocument(myID);
924 // after all updates, sends a message that groups of features were created or updated
925 Events_Loop* aLoop = Events_Loop::loop();
926 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
927 static Events_ID aCreateEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
928 static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
929 static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
930 static Events_ID aDeleteEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
931 static Events_ID aToHideEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
932 aLoop->activateFlushes(false);
934 // update all objects by checking are they of labels or not
935 std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
936 TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
937 for (; aLabIter.More(); aLabIter.Next()) {
938 TDF_Label aFeatureLabel = aLabIter.Value()->Label();
940 if (!myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted
942 aFeature = ModelAPI_Session::get()->createFeature(
943 TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
945 if (!aFeature) { // somethig is wrong, most probably, the opened document has invalid structure
946 Events_Error::send("Invalid type of object in the document");
947 aLabIter.Value()->Label().ForgetAllAttributes();
950 // this must be before "setData" to redo the sketch line correctly
951 myObjs.Bind(aFeatureLabel, aFeature);
952 aNewFeatures.insert(aFeature);
953 initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
955 // event: model is updated
956 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aCreateEvent);
957 } else { // nothing is changed, both iterators are incremented
958 aFeature = myObjs.Find(aFeatureLabel);
959 aKeptFeatures.insert(aFeature);
960 if (theMarkUpdated) {
961 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anUpdateEvent);
965 // update results of the features (after features created because they may be connected, like sketch and sub elements)
966 std::list<FeaturePtr> aComposites; // composites must be updated after their subs (issue 360)
967 TDF_ChildIDIterator aLabIter2(featuresLabel(), TDataStd_Comment::GetID());
968 for (; aLabIter2.More(); aLabIter2.Next()) {
969 TDF_Label aFeatureLabel = aLabIter2.Value()->Label();
970 if (myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted
971 FeaturePtr aFeature = myObjs.Find(aFeatureLabel);
972 if (std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature).get())
973 aComposites.push_back(aFeature);
974 updateResults(aFeature);
977 std::list<FeaturePtr>::iterator aComposite = aComposites.begin();
978 for(; aComposite != aComposites.end(); aComposite++) {
979 updateResults(*aComposite);
982 // check all features are checked: if not => it was removed
983 NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myObjs);
984 while (aFIter.More()) {
985 if (aKeptFeatures.find(aFIter.Value()) == aKeptFeatures.end()
986 && aNewFeatures.find(aFIter.Value()) == aNewFeatures.end()) {
987 FeaturePtr aFeature = aFIter.Value();
988 // event: model is updated
989 //if (aFeature->isInHistory()) {
990 ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Feature::group());
992 // results of this feature must be redisplayed (hided)
993 // redisplay also removed feature (used for sketch and AISObject)
994 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aRedispEvent);
996 // unbind after the "erase" call: on abort sketch is removes sub-objects that corrupts aFIter
997 myObjs.UnBind(aFIter.Key());
998 // reinitialize iterator because unbind may corrupt the previous order in the map
999 aFIter.Initialize(myObjs);
1004 if (theUpdateReferences) {
1005 synchronizeBackRefs();
1008 myExecuteFeatures = false;
1009 aLoop->activateFlushes(true);
1011 aLoop->flush(aCreateEvent);
1012 aLoop->flush(aDeleteEvent);
1013 aLoop->flush(anUpdateEvent);
1014 aLoop->flush(aRedispEvent);
1015 aLoop->flush(aToHideEvent);
1016 myExecuteFeatures = true;
1019 void Model_Document::synchronizeBackRefs()
1021 std::shared_ptr<ModelAPI_Document> aThis =
1022 Model_Application::getApplication()->getDocument(myID);
1023 // keeps the concealed flags of result to catch the change and create created/deleted events
1024 std::list<std::pair<ResultPtr, bool> > aConcealed;
1025 // first cycle: erase all data about back-references
1026 NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myObjs);
1027 for(; aFeatures.More(); aFeatures.Next()) {
1028 FeaturePtr aFeature = aFeatures.Value();
1029 std::shared_ptr<Model_Data> aFData =
1030 std::dynamic_pointer_cast<Model_Data>(aFeature->data());
1032 aFData->eraseBackReferences();
1034 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
1035 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
1036 for (; aRIter != aResults.cend(); aRIter++) {
1037 std::shared_ptr<Model_Data> aResData =
1038 std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
1040 aConcealed.push_back(std::pair<ResultPtr, bool>(*aRIter, (*aRIter)->isConcealed()));
1041 aResData->eraseBackReferences();
1046 // second cycle: set new back-references: only features may have reference, iterate only them
1047 ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
1048 for(aFeatures.Initialize(myObjs); aFeatures.More(); aFeatures.Next()) {
1049 FeaturePtr aFeature = aFeatures.Value();
1050 std::shared_ptr<Model_Data> aFData =
1051 std::dynamic_pointer_cast<Model_Data>(aFeature->data());
1053 std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
1054 aFData->referencesToObjects(aRefs);
1055 std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
1056 for(; aRefsIter != aRefs.end(); aRefsIter++) {
1057 std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
1058 for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
1060 std::shared_ptr<Model_Data> aRefData =
1061 std::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
1062 aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
1068 std::list<std::pair<ResultPtr, bool> >::iterator aCIter = aConcealed.begin();
1069 for(; aCIter != aConcealed.end(); aCIter++) {
1070 if (aCIter->first->isConcealed() != aCIter->second) { // somethign is changed => produce event
1071 if (aCIter->second) { // was concealed become not => creation event
1072 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
1073 ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, anEvent);
1074 } else { // was not concealed become concealed => delete event
1075 ModelAPI_EventCreator::get()->sendDeleted(aThis, aCIter->first->groupName());
1076 // redisplay for the viewer (it must be disappeared also)
1077 static Events_ID EVENT_DISP =
1078 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1079 ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, EVENT_DISP);
1085 TDF_Label Model_Document::resultLabel(
1086 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex)
1088 const std::shared_ptr<Model_Data>& aData =
1089 std::dynamic_pointer_cast<Model_Data>(theFeatureData);
1090 return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
1093 void Model_Document::storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
1094 std::shared_ptr<ModelAPI_Result> theResult,
1095 const int theResultIndex)
1097 std::shared_ptr<ModelAPI_Document> aThis =
1098 Model_Application::getApplication()->getDocument(myID);
1099 theResult->setDoc(aThis);
1100 initData(theResult, resultLabel(theFeatureData, theResultIndex), TAG_FEATURE_ARGUMENTS);
1101 if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
1102 theResult->data()->setName(theFeatureData->name());
1106 std::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
1107 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
1109 TDF_Label aLab = resultLabel(theFeatureData, theIndex);
1110 TDataStd_Comment::Set(aLab, ModelAPI_ResultConstruction::group().c_str());
1111 ObjectPtr anOldObject = object(aLab);
1112 std::shared_ptr<ModelAPI_ResultConstruction> aResult;
1114 aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anOldObject);
1117 aResult = std::shared_ptr<ModelAPI_ResultConstruction>(new Model_ResultConstruction);
1118 storeResult(theFeatureData, aResult, theIndex);
1123 std::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
1124 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
1126 TDF_Label aLab = resultLabel(theFeatureData, theIndex);
1127 TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
1128 ObjectPtr anOldObject = object(aLab);
1129 std::shared_ptr<ModelAPI_ResultBody> aResult;
1131 aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anOldObject);
1134 aResult = std::shared_ptr<ModelAPI_ResultBody>(new Model_ResultBody);
1135 storeResult(theFeatureData, aResult, theIndex);
1140 std::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
1141 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
1143 TDF_Label aLab = resultLabel(theFeatureData, theIndex);
1144 TDataStd_Comment::Set(aLab, ModelAPI_ResultPart::group().c_str());
1145 ObjectPtr anOldObject = object(aLab);
1146 std::shared_ptr<ModelAPI_ResultPart> aResult;
1148 aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anOldObject);
1151 aResult = std::shared_ptr<ModelAPI_ResultPart>(new Model_ResultPart);
1152 storeResult(theFeatureData, aResult, theIndex);
1157 std::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
1158 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
1160 TDF_Label aLab = resultLabel(theFeatureData, theIndex);
1161 TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str());
1162 ObjectPtr anOldObject = object(aLab);
1163 std::shared_ptr<ModelAPI_ResultGroup> aResult;
1165 aResult = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(anOldObject);
1168 aResult = std::shared_ptr<ModelAPI_ResultGroup>(new Model_ResultGroup(theFeatureData));
1169 storeResult(theFeatureData, aResult, theIndex);
1174 std::shared_ptr<ModelAPI_Feature> Model_Document::feature(
1175 const std::shared_ptr<ModelAPI_Result>& theResult)
1177 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theResult->data());
1179 TDF_Label aFeatureLab = aData->label().Father().Father().Father();
1180 return feature(aFeatureLab);
1182 return FeaturePtr();
1185 void Model_Document::updateResults(FeaturePtr theFeature)
1187 // for not persistent is will be done by parametric updater automatically
1188 //if (!theFeature->isPersistentResult()) return;
1189 // check the existing results and remove them if there is nothing on the label
1190 std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
1191 while(aResIter != theFeature->results().cend()) {
1192 ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(*aResIter);
1194 if (!aBody->data()->isValid()) {
1195 // found a disappeared result => remove it
1196 theFeature->removeResult(aBody);
1197 // start iterate from beginning because iterator is corrupted by removing
1198 aResIter = theFeature->results().cbegin();
1204 // it may be on undo
1205 if (!theFeature->data() || !theFeature->data()->isValid())
1207 // check that results are presented on all labels
1208 int aResSize = theFeature->results().size();
1209 TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father());
1210 for(; aLabIter.More(); aLabIter.Next()) {
1211 // here must be GUID of the feature
1212 int aResIndex = aLabIter.Value().Tag() - 1;
1214 if (aResSize <= aResIndex) {
1215 TDF_Label anArgLab = aLabIter.Value();
1216 Handle(TDataStd_Comment) aGroup;
1217 if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
1218 if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
1219 aNewBody = createBody(theFeature->data(), aResIndex);
1220 } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
1221 aNewBody = createPart(theFeature->data(), aResIndex);
1222 } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
1223 theFeature->execute(); // construction shapes are needed for sketch solver
1225 } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) {
1226 aNewBody = createGroup(theFeature->data(), aResIndex);
1228 Events_Error::send(std::string("Unknown type of result is found in the document:") +
1229 TCollection_AsciiString(aGroup->Get()).ToCString());
1233 theFeature->setResult(aNewBody, aResIndex);
1239 Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
1241 return TDF_LabelMapHasher::HashCode(theLab, theUpper);
1244 Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2)
1246 return TDF_LabelMapHasher::IsEqual(theLab1, theLab2);
1249 void Model_Document::addNamingName(const TDF_Label theLabel, std::string theName)
1251 myNamingNames[theName] = theLabel;
1254 TDF_Label Model_Document::findNamingName(std::string theName)
1256 std::map<std::string, TDF_Label>::iterator aFind = myNamingNames.find(theName);
1257 if (aFind == myNamingNames.end())
1258 return TDF_Label(); // not found
1259 return aFind->second;
1262 ResultPtr Model_Document::findByName(const std::string theName)
1264 NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myObjs);
1265 for(; anObjIter.More(); anObjIter.Next()) {
1266 FeaturePtr& aFeature = anObjIter.ChangeValue();
1267 if (!aFeature) // may be on close
1269 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
1270 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
1271 for (; aRIter != aResults.cend(); aRIter++) {
1272 if (aRIter->get() && (*aRIter)->data() && (*aRIter)->data()->isValid() &&
1273 (*aRIter)->data()->name() == theName) {