+ }
+ }
+}
+
+TDF_Label Model_Document::resultLabel(
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex)
+{
+ const std::shared_ptr<Model_Data>& aData =
+ std::dynamic_pointer_cast<Model_Data>(theFeatureData);
+ return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
+}
+
+void Model_Document::storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ const int theResultIndex)
+{
+ std::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ theResult->setDoc(aThis);
+ 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());
+ }
+}
+
+std::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultConstruction::group().c_str());
+ ObjectPtr anOldObject = object(aLab);
+ std::shared_ptr<ModelAPI_ResultConstruction> aResult;
+ if (anOldObject) {
+ aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anOldObject);
+ }
+ if (!aResult) {
+ aResult = std::shared_ptr<ModelAPI_ResultConstruction>(new Model_ResultConstruction);
+ storeResult(theFeatureData, aResult, theIndex);
+ }
+ return aResult;
+}
+
+std::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
+ ObjectPtr anOldObject = object(aLab);
+ std::shared_ptr<ModelAPI_ResultBody> aResult;
+ if (anOldObject) {
+ aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anOldObject);
+ }
+ if (!aResult) {
+ aResult = std::shared_ptr<ModelAPI_ResultBody>(new Model_ResultBody);
+ storeResult(theFeatureData, aResult, theIndex);
+ }
+ return aResult;
+}
+
+std::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultPart::group().c_str());
+ ObjectPtr anOldObject = object(aLab);
+ std::shared_ptr<ModelAPI_ResultPart> aResult;
+ if (anOldObject) {
+ aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anOldObject);
+ }
+ if (!aResult) {
+ aResult = std::shared_ptr<ModelAPI_ResultPart>(new Model_ResultPart);
+ storeResult(theFeatureData, aResult, theIndex);
+ }
+ return aResult;
+}
+
+std::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str());
+ ObjectPtr anOldObject = object(aLab);
+ std::shared_ptr<ModelAPI_ResultGroup> aResult;
+ if (anOldObject) {
+ aResult = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(anOldObject);
+ }
+ if (!aResult) {
+ aResult = std::shared_ptr<ModelAPI_ResultGroup>(new Model_ResultGroup(theFeatureData));
+ storeResult(theFeatureData, aResult, theIndex);
+ }
+ return aResult;
+}
+
+std::shared_ptr<ModelAPI_Feature> Model_Document::feature(
+ const std::shared_ptr<ModelAPI_Result>& theResult)
+{
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theResult->data());
+ if (aData) {
+ TDF_Label aFeatureLab = aData->label().Father().Father().Father();
+ return feature(aFeatureLab);
+ }
+ 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()) {
+ ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(*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++;
+ }
+ // it may be on undo
+ if (!theFeature->data() || !theFeature->data()->isValid())
+ return;
+ // 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();
+ Handle(TDataStd_Comment) aGroup;
+ if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
+ if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
+ aNewBody = createBody(theFeature->data(), aResIndex);
+ } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
+ aNewBody = createPart(theFeature->data(), aResIndex);
+ } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
+ theFeature->execute(); // construction shapes are needed for sketch solver
+ break;
+ } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) {
+ aNewBody = createGroup(theFeature->data(), aResIndex);