+ // something is not right
+ return "";
+ }
+
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return "";
+
+ // getting an access to the document of part
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(partDoc());
+ if (!aDoc.get()) // the part document is not presented for the moment
+ return "";
+ TDF_Label anAccessLabel = aDoc->generalLabel();
+ // make the selection attribute anyway:
+ // otherwise just by name it is not stable to search the result
+ std::string aName;
+ // for this the context result is needed
+ ResultPtr aContext;
+ const std::string& aBodyGroup = ModelAPI_ResultBody::group();
+ for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) {
+ ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
+ if (aBody.get() && aBody->shape().get() && !aBody->isDisabled()) {
+ TopoDS_Shape aBodyShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
+ // check is body contain the selected sub-shape
+ for(TopExp_Explorer anExp(aBodyShape, aShape.ShapeType()); anExp.More(); anExp.Next()) {
+ if (aShape.IsEqual(anExp.Current())) {
+ aContext = aBody;
+ break;
+ }
+ }
+ }
+ }
+ if (aContext.get()) {
+ AttributeSelectionListPtr aSelAttr = aDoc->selectionInPartFeature();
+ aSelAttr->append(aContext, theShape);
+ theIndex = aSelAttr->size();
+ AttributeSelectionPtr aNewAttr = aSelAttr->value(theIndex - 1);
+ return aNewAttr->namingName();
+ }
+ return aName;
+}
+
+bool Model_ResultPart::updateInPart(const int theIndex)
+{
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(partDoc());
+ if (aDoc.get()) {
+ AttributeSelectionListPtr aSelAttr = aDoc->selectionInPartFeature();
+ AttributeSelectionPtr aThisAttr = aSelAttr->value(theIndex - 1);
+ if (aThisAttr.get()) {
+ return aThisAttr->update();
+ }
+ }
+ return false; // something is wrong
+}
+
+gp_Trsf Model_ResultPart::sumTrsf() {
+ gp_Trsf aResult;
+ if (myTrsf) {
+ aResult = *myTrsf;
+ aResult = aResult * baseRef()->sumTrsf();
+ }
+ return aResult;
+}
+
+std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shapeInPart(
+ const std::string& theName, const std::string& theType, int& theIndex)
+{
+ theIndex = 0; // not found yet
+ std::shared_ptr<GeomAPI_Shape> aResult;
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(partDoc());
+ if (!aDoc.get()) // the part document is not presented for the moment
+ return aResult;
+
+ AttributeSelectionListPtr aSelAttr = aDoc->selectionInPartFeature();
+ // check this selection is already there: reuse it
+ int aSize = aSelAttr->size();
+ for(int a = 0; a < aSize; a++) {
+ if (aSelAttr->value(a)->namingName() == theName) {
+ theIndex = a;
+ return aSelAttr->value(a)->value();
+ }
+ }
+
+ aSelAttr->append(theName, theType);
+ theIndex = aSelAttr->size();
+ aResult = aSelAttr->value(theIndex - 1)->value();
+ if (myTrsf.get() && aResult.get() && !aResult->isNull()) {
+ gp_Trsf aSumTrsf = sumTrsf();
+ TopoDS_Shape anOrigMoved = aResult->impl<TopoDS_Shape>().Moved(aSumTrsf);
+ aResult->setImpl(new TopoDS_Shape(anOrigMoved));
+ }
+ return aResult;
+}
+
+std::shared_ptr<GeomAPI_Shape> Model_ResultPart::selectionValue(const int theIndex)
+{
+ std::shared_ptr<GeomAPI_Shape> aResult;
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(partDoc());
+ if (!aDoc.get()) // the part document is not presented for the moment
+ return aResult;
+
+ AttributeSelectionListPtr aSelAttr = aDoc->selectionInPartFeature();
+ aResult = aSelAttr->value(theIndex - 1)->value();
+ if (myTrsf.get() && aResult.get() && !aResult->isNull()) {
+ gp_Trsf aSumTrsf = sumTrsf();
+ TopoDS_Shape anOrigMoved = aResult->impl<TopoDS_Shape>().Moved(aSumTrsf);
+ aResult->setImpl(new TopoDS_Shape(anOrigMoved));
+ }
+ return aResult;
+}
+
+void Model_ResultPart::colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault)
+{
+ theSection = "Visualization";
+ theName = "result_part_color";
+ theDefault = DEFAULT_COLOR();
+}
+
+void Model_ResultPart::updateShape()
+{
+ myShape.Nullify();
+ myTrsf.reset();
+}
+
+void Model_ResultPart::setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
+ const std::shared_ptr<GeomAPI_Trsf>& theTransformation)
+{
+ updateShape();
+ if (theTransformation.get()) {
+ myTrsf = std::shared_ptr<gp_Trsf>(new gp_Trsf(theTransformation->impl<gp_Trsf>()));