1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "Model_AttributeSelection.h"
22 #include "Model_Application.h"
23 #include "Model_Events.h"
24 #include "Model_Data.h"
25 #include "Model_Document.h"
26 #include "Model_SelectionNaming.h"
27 #include <Model_Objects.h>
28 #include <Model_AttributeSelectionList.h>
29 #include <Model_ResultConstruction.h>
30 #include <ModelAPI_Feature.h>
31 #include <ModelAPI_ResultBody.h>
32 #include <ModelAPI_ResultBody.h>
33 #include <ModelAPI_ResultConstruction.h>
34 #include <ModelAPI_ResultPart.h>
35 #include <ModelAPI_CompositeFeature.h>
36 #include <ModelAPI_Tools.h>
37 #include <ModelAPI_Session.h>
38 #include <ModelAPI_Validator.h>
39 #include <ModelGeomAlgo_Shape.h>
40 #include <Events_InfoMessage.h>
41 #include <GeomAPI_Edge.h>
42 #include <GeomAPI_Pnt.h>
43 #include <GeomAPI_Vertex.h>
44 #include <GeomAlgoAPI_CompoundBuilder.h>
45 #include <GeomAlgoAPI_NExplode.h>
47 #include <TNaming_Selector.hxx>
48 #include <TNaming_NamedShape.hxx>
49 #include <TNaming_Tool.hxx>
50 #include <TNaming_Builder.hxx>
51 #include <TNaming_SameShapeIterator.hxx>
52 #include <TNaming_Iterator.hxx>
53 #include <TDataStd_Integer.hxx>
54 #include <TDataStd_UAttribute.hxx>
55 #include <TDataStd_Name.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopTools_DataMapOfShapeShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <TopExp_Explorer.hxx>
60 #include <BRep_Tool.hxx>
63 #include <TDF_ChildIterator.hxx>
64 #include <TDF_ChildIDIterator.hxx>
65 #include <TopoDS_Iterator.hxx>
66 #include <TDF_ChildIDIterator.hxx>
67 #include <Geom_Circle.hxx>
68 #include <Geom_Ellipse.hxx>
69 #include <BRep_Builder.hxx>
71 //#define DEB_NAMING 1
73 #include <BRepTools.hxx>
75 /// added to the index in the packed map to signalize that the vertex of edge is selected
76 /// (multiplied by the index of the edge)
77 static const int kSTART_VERTEX_DELTA = 1000000;
78 // identifier that there is simple reference: selection equals to context
79 Standard_GUID kSIMPLE_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb29");
80 // reference to Part sub-object
81 Standard_GUID kPART_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb27");
82 // selection is invalid after recomputation
83 Standard_GUID kINVALID_SELECTION("bce47fd7-80fa-4462-9d63-2f58acddd49d");
85 // identifier of the selection of the center of circle on edge
86 Standard_GUID kCIRCLE_CENTER("d0d0e0f1-217a-4b95-8fbb-0c4132f23718");
87 // identifier of the selection of the first focus point of ellipse on edge
88 Standard_GUID kELLIPSE_CENTER1("f70df04c-3168-4dc9-87a4-f1f840c1275d");
89 // identifier of the selection of the second focus point of ellipse on edge
90 Standard_GUID kELLIPSE_CENTER2("1395ae73-8e02-4cf8-b204-06ff35873a32");
91 // identifier of the weak naming index
92 Standard_GUID kWEAK_NAMING("9dcdd9be-a3a9-46eb-9b16-1c957ab20142");
93 // identifier of the weak naming sub-shape type
94 Standard_GUID kWEAK_NAMING_SHAPETYPE("6b9cc709-e320-4a1f-9c42-df5622369ea7");
96 // prefix for the whole feature context identification
97 const static std::string kWHOLE_FEATURE = "all-in-";
99 // on this label is stored:
100 // TNaming_NamedShape - selected shape
101 // TNaming_Naming - topological selection information (for the body)
102 // TDataStd_IntPackedMap - indexes of edges in composite element (for construction)
103 // TDataStd_Integer - type of the selected shape (for construction)
104 // TDF_Reference - from ReferenceAttribute, the context
105 bool Model_AttributeSelection::setValue(const ObjectPtr& theContext,
106 const std::shared_ptr<GeomAPI_Shape>& theSubShape, const bool theTemporarily)
108 if (theTemporarily &&
109 (!theContext.get() || theContext->groupName() != ModelAPI_Feature::group())) {
110 // just keep the stored without DF update
111 myTmpContext = std::dynamic_pointer_cast<ModelAPI_Result>(theContext);
112 myTmpSubShape = theSubShape;
113 owner()->data()->sendAttributeUpdated(this);
116 myTmpContext.reset();
117 myTmpSubShape.reset();
118 myTmpCenterType = NOT_CENTER;
122 const std::shared_ptr<GeomAPI_Shape>& anOldShape = internalValue(aType);
123 bool isOldContext = theContext == myRef.value();
124 bool isOldShape = isOldContext &&
125 (theSubShape == anOldShape || (theSubShape && anOldShape && theSubShape->isEqual(anOldShape)));
126 if (isOldShape) return false; // shape is the same, so context is also unchanged
127 bool aToUnblock = false;
128 // update the referenced object if needed
130 aToUnblock = !owner()->data()->blockSendAttributeUpdated(true);
131 myRef.setValue(theContext);
134 // do noth use naming if selected shape is result shape itself, but not sub-shape
135 TDF_Label aSelLab = selectionLabel();
136 aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
137 aSelLab.ForgetAttribute(kINVALID_SELECTION);
138 aSelLab.ForgetAttribute(kCIRCLE_CENTER);
139 aSelLab.ForgetAttribute(kELLIPSE_CENTER1);
140 aSelLab.ForgetAttribute(kELLIPSE_CENTER2);
141 aSelLab.ForgetAttribute(kWEAK_NAMING);
142 aSelLab.ForgetAttribute(kWEAK_NAMING_SHAPETYPE);
144 bool isDegeneratedEdge = false;
145 // do not use the degenerated edge as a shape, a null context and shape is used in the case
146 if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
147 const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
148 if (aSubShape.ShapeType() == TopAbs_EDGE)
149 isDegeneratedEdge = BRep_Tool::Degenerated(TopoDS::Edge(aSubShape)) == Standard_True;
151 if (!theContext.get() || isDegeneratedEdge) {
152 // to keep the reference attribute label
153 TDF_Label aRefLab = myRef.myRef->Label();
154 aSelLab.ForgetAllAttributes(true);
155 myRef.myRef = TDF_Reference::Set(aSelLab.Father(), aSelLab.Father());
157 owner()->data()->blockSendAttributeUpdated(false);
160 if (theContext->groupName() == ModelAPI_ResultBody::group()) {
161 ResultBodyPtr aContextBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theContext);
162 // do not select the whole shape for body:it is already must be in the data framework
163 // equal and null selected objects mean the same: object is equal to context,
164 if (aContextBody->shape().get() &&
165 (aContextBody->shape()->isEqual(theSubShape) || !theSubShape.get())) {
166 aSelLab.ForgetAllAttributes(true);
167 TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
169 selectBody(aContextBody, theSubShape);
171 } else if (theContext->groupName() == ModelAPI_ResultConstruction::group()) {
172 ResultConstructionPtr aContextConstruction =
173 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theContext);
174 aSelLab.ForgetAllAttributes(true); // to remove old selection data
175 std::shared_ptr<Model_ResultConstruction> aConstruction =
176 std::dynamic_pointer_cast<Model_ResultConstruction>(theContext);
177 std::shared_ptr<GeomAPI_Shape> aSubShape;
178 if (theSubShape.get() && !aContextConstruction->shape()->isEqual(theSubShape))
179 aSubShape = theSubShape; // the whole context
180 if (aConstruction->isInfinite()) {
181 // For correct naming selection, put the shape into the naming structure.
182 // It seems sub-shapes are not needed: only this shape is (and can be ) selected.
183 TNaming_Builder aBuilder(aSelLab);
184 aBuilder.Generated(aContextConstruction->shape()->impl<TopoDS_Shape>());
186 int anIndex = aConstruction->select(theSubShape, owner()->document());
187 TDataStd_Integer::Set(aSelLab, anIndex);
188 } else if (theContext->groupName() == ModelAPI_ResultPart::group()) {
189 aSelLab.ForgetAllAttributes(true);
190 TDataStd_UAttribute::Set(aSelLab, kPART_REF_ID);
191 selectPart(std::dynamic_pointer_cast<ModelAPI_Result>(theContext), theSubShape);
192 } else { // check the feature context: parent-Part of this feature should not be used
193 FeaturePtr aFeatureContext = std::dynamic_pointer_cast<ModelAPI_Feature>(theContext);
194 if (aFeatureContext.get()) {
195 if (owner()->document() != aFeatureContext->document()) {
196 aSelLab.ForgetAllAttributes(true);
197 myRef.setValue(ObjectPtr());
199 owner()->data()->blockSendAttributeUpdated(false);
205 owner()->data()->sendAttributeUpdated(this);
208 owner()->data()->blockSendAttributeUpdated(false);
213 void Model_AttributeSelection::setValueCenter(
214 const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Edge>& theEdge,
215 const CenterType theCenterType, const bool theTemporarily)
217 bool anUpdated = setValue(theContext, theEdge, theTemporarily);
218 if (theTemporarily) {
219 myTmpCenterType = theCenterType;
220 } else { // store in the data structure
221 TDF_Label aSelLab = selectionLabel();
222 switch(theCenterType) {
225 anUpdated = !aSelLab.IsAttribute(kCIRCLE_CENTER);
226 TDataStd_UAttribute::Set(aSelLab, kCIRCLE_CENTER);
228 case ELLIPSE_FIRST_FOCUS:
230 anUpdated = !aSelLab.IsAttribute(kELLIPSE_CENTER1);
231 TDataStd_UAttribute::Set(aSelLab, kELLIPSE_CENTER1);
233 case ELLIPSE_SECOND_FOCUS:
235 anUpdated = !aSelLab.IsAttribute(kELLIPSE_CENTER2);
236 TDataStd_UAttribute::Set(aSelLab, kELLIPSE_CENTER2);
240 owner()->data()->sendAttributeUpdated(this);
244 void Model_AttributeSelection::selectValue(
245 const std::shared_ptr<ModelAPI_AttributeSelection>& theSource)
248 std::shared_ptr<GeomAPI_Shape> aValue =
249 std::dynamic_pointer_cast<Model_AttributeSelection>(theSource)->internalValue(aType);
250 if (!aValue.get() || aType == NOT_CENTER) {
251 setValue(theSource->context(), aValue);
253 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
254 anEdge->setImpl(new TopoDS_Shape(aValue->impl<TopoDS_Shape>()));
255 setValueCenter(theSource->context(), anEdge, aType);
259 void Model_AttributeSelection::removeTemporaryValues()
261 if (myTmpContext.get() || myTmpSubShape.get()) {
262 myTmpContext.reset();
263 myTmpSubShape.reset();
267 // returns the center of the edge: circular or elliptical
268 GeomShapePtr centerByEdge(GeomShapePtr theEdge, ModelAPI_AttributeSelection::CenterType theType)
270 if (theType != ModelAPI_AttributeSelection::NOT_CENTER && theEdge.get() != NULL) {
271 TopoDS_Shape aShape = theEdge->impl<TopoDS_Shape>();
272 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) {
273 TopoDS_Edge anEdge = TopoDS::Edge(aShape);
274 double aFirst, aLast;
275 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
276 if (!aCurve.IsNull()) {
277 TopoDS_Vertex aVertex;
278 BRep_Builder aBuilder;
279 if (theType == ModelAPI_AttributeSelection::CIRCLE_CENTER) {
280 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
281 if (!aCirc.IsNull()) {
282 aBuilder.MakeVertex(aVertex, aCirc->Location(), Precision::Confusion());
285 Handle(Geom_Ellipse) anEll = Handle(Geom_Ellipse)::DownCast(aCurve);
286 if (!anEll.IsNull()) {
287 aBuilder.MakeVertex(aVertex,
288 theType == ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS ?
289 anEll->Focus1() : anEll->Focus2(), Precision::Confusion());
292 if (!aVertex.IsNull()) {
293 std::shared_ptr<GeomAPI_Vertex> aResult(new GeomAPI_Vertex);
294 aResult->setImpl(new TopoDS_Vertex(aVertex));
300 return theEdge; // no vertex, so, return the initial edge
303 std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
305 if (!ModelAPI_AttributeSelection::isInitialized() && !myTmpContext.get() && !myTmpSubShape.get())
306 return std::shared_ptr<GeomAPI_Shape>();
307 CenterType aType = NOT_CENTER;
308 std::shared_ptr<GeomAPI_Shape> aResult = internalValue(aType);
309 return centerByEdge(aResult, aType);
312 std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::internalValue(CenterType& theType)
314 theType = NOT_CENTER;
315 GeomShapePtr aResult;
316 if (myTmpContext.get() || myTmpSubShape.get()) {
317 theType = myTmpCenterType;
318 ResultConstructionPtr aResulConstruction =
319 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myTmpContext);
320 if(aResulConstruction.get()) {
321 // it is just reference to construction.
322 return myTmpSubShape;
324 return myTmpSubShape.get() ? myTmpSubShape : myTmpContext->shape();
327 TDF_Label aSelLab = selectionLabel();
328 if (aSelLab.IsAttribute(kINVALID_SELECTION))
331 if (aSelLab.IsAttribute(kCIRCLE_CENTER))
332 theType = CIRCLE_CENTER;
333 else if (aSelLab.IsAttribute(kELLIPSE_CENTER1))
334 theType = ELLIPSE_FIRST_FOCUS;
335 else if (aSelLab.IsAttribute(kELLIPSE_CENTER2))
336 theType = ELLIPSE_SECOND_FOCUS;
339 if (myRef.isInitialized()) {
340 if (aSelLab.IsAttribute(kSIMPLE_REF_ID)) { // it is just reference to shape, not sub-shape
341 ResultPtr aContext = context();
343 return aResult; // empty result
344 return aContext->shape();
346 if (aSelLab.IsAttribute(kPART_REF_ID)) {
347 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(context());
348 if (!aPart.get() || !aPart->isActivated())
349 return std::shared_ptr<GeomAPI_Shape>(); // postponed naming needed
350 Handle(TDataStd_Integer) anIndex;
351 if (aSelLab.FindAttribute(TDataStd_Integer::GetID(), anIndex)) {
352 if (anIndex->Get()) { // special selection attribute was created, use it
353 return aPart->selectionValue(anIndex->Get());
354 } else { // face with name is already in the data model, so try to take it by name
355 Handle(TDataStd_Name) aName;
356 if (aSelLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
357 std::string aSubShapeName(TCollection_AsciiString(aName->Get()).ToCString());
358 std::size_t aPartEnd = aSubShapeName.find('/');
359 if (aPartEnd != std::string::npos && aPartEnd != aSubShapeName.rfind('/')) {
360 std::string aNameInPart = aSubShapeName.substr(aPartEnd + 1);
362 std::string aType; // to reuse already existing selection the type is not needed
363 return aPart->shapeInPart(aNameInPart, aType, anIndex);
370 std::shared_ptr<Model_ResultConstruction> aConstr =
371 std::dynamic_pointer_cast<Model_ResultConstruction>(context());
373 if (aConstr->isInfinite())
374 return aResult; // empty result
376 if (!aConstr.get()) { // for construction context, return empty result as usual even
377 // the whole feature is selected
378 FeaturePtr aFeature = contextFeature();
379 if (aFeature.get()) {
380 std::list<GeomShapePtr> allShapes;
381 std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
382 for (; aRes != aFeature->results().cend(); aRes++) {
383 if (aRes->get() && !(*aRes)->isDisabled()) {
384 GeomShapePtr aShape = (*aRes)->shape();
385 if (aShape.get() && !aShape->isNull()) {
386 allShapes.push_back(aShape);
390 return GeomAlgoAPI_CompoundBuilder::compound(allShapes);
394 if (aSelLab.IsAttribute(kWEAK_NAMING)) { // a weak naming is used
395 Handle(TDataStd_Integer) aWeakId;
396 aSelLab.FindAttribute(kWEAK_NAMING, aWeakId);
397 // get the context shape
398 GeomShapePtr aContextShape;
399 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(context());
401 aContextShape = aBody->shape();
403 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
405 aContextShape = aResult->shape();
408 if (!aContextShape.get())
409 return GeomShapePtr();
410 Handle(TDataStd_Integer) aWeakShapeType;
411 aSelLab.FindAttribute(kWEAK_NAMING_SHAPETYPE, aWeakShapeType);
412 GeomAlgoAPI_NExplode aNExplode(
413 aContextShape, GeomAPI_Shape::ShapeType(aWeakShapeType->Get()));
414 GeomShapePtr aValue = aNExplode.shape(aWeakId->Get());
418 Handle(TNaming_NamedShape) aSelection;
419 if (aSelLab.FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
420 TopoDS_Shape aSelShape = aSelection->Get();
421 aResult = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
422 aResult->setImpl(new TopoDS_Shape(aSelShape));
423 } else if (aConstr) { // simple construction element: just shape of this construction element
424 Handle(TDataStd_Integer) anIndex;
425 if (aSelLab.FindAttribute(TDataStd_Integer::GetID(), anIndex)) {
426 if (anIndex->Get() == 0) // it is just reference to construction, nothing is in value
428 return aConstr->shape(anIndex->Get(), owner()->document());
435 bool Model_AttributeSelection::isInvalid()
437 return selectionLabel().IsAttribute(kINVALID_SELECTION) == Standard_True;
440 bool Model_AttributeSelection::isInitialized()
442 if (ModelAPI_AttributeSelection::isInitialized()) { // additional checks if it is initialized
443 std::shared_ptr<GeomAPI_Shape> aResult;
444 if (myRef.isInitialized()) {
445 TDF_Label aSelLab = selectionLabel();
446 if (aSelLab.IsAttribute(kSIMPLE_REF_ID)) { // it is just reference to shape, not sub-shape
447 ResultPtr aContext = context();
448 return aContext.get() != NULL;
450 Handle(TNaming_NamedShape) aSelection;
451 if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
452 return !aSelection->Get().IsNull();
453 } else { // for simple construction element: just shape of this construction element
454 std::shared_ptr<Model_ResultConstruction> aConstr =
455 std::dynamic_pointer_cast<Model_ResultConstruction>(context());
457 Handle(TDataStd_Integer) anIndex;
458 if (aSelLab.FindAttribute(TDataStd_Integer::GetID(), anIndex)) {
459 // for the whole shape it may return null, so, if index exists, returns true
463 // for the whole feature, a feature object
464 FeaturePtr aFeat = contextFeature();
473 Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
476 myIsInitialized = myRef.isInitialized();
480 void Model_AttributeSelection::setID(const std::string theID)
483 ModelAPI_AttributeSelection::setID(theID);
486 ResultPtr Model_AttributeSelection::context()
488 if (!ModelAPI_AttributeSelection::isInitialized() && !myTmpContext.get() && !myTmpSubShape.get())
491 if (myTmpContext.get() || myTmpSubShape.get()) {
495 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
496 // for parts there could be same-data result, so take the last enabled
498 if(aResult->groupName() == ModelAPI_ResultPart::group()) {
499 int aSize = aResult->document()->size(ModelAPI_ResultPart::group());
500 for(int a = aSize - 1; a >= 0; a--) {
501 ObjectPtr aPart = aResult->document()->object(ModelAPI_ResultPart::group(), a);
502 if(aPart.get() && aPart->data() == aResult->data()) {
503 ResultPtr aPartResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPart);
504 FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
505 // check that this result is not this-feature result (it is forbidden t oselect itself)
506 if(anOwnerFeature.get() && anOwnerFeature->firstResult() != aPartResult) {
512 } else { // if feature - construction is selected, it has only one result, return this result
513 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(myRef.value());
514 if (aFeature.get() && aFeature->results().size() == 1 &&
515 aFeature->firstResult()->groupName() == ModelAPI_ResultConstruction::group())
516 return aFeature->firstResult();
521 FeaturePtr Model_AttributeSelection::contextFeature() {
522 if (myTmpContext.get() || myTmpSubShape.get()) {
523 return FeaturePtr(); // feature can not be selected temporarily
525 return std::dynamic_pointer_cast<ModelAPI_Feature>(myRef.value());
527 ObjectPtr Model_AttributeSelection::contextObject() {
528 FeaturePtr aRes = contextFeature();
535 void Model_AttributeSelection::setObject(const std::shared_ptr<ModelAPI_Object>& theObject)
537 ModelAPI_AttributeSelection::setObject(theObject);
538 myRef.setObject(theObject);
541 TDF_LabelMap& Model_AttributeSelection::scope()
543 if (myScope.IsEmpty()) { // create a new scope if not yet done
544 // gets all features with named shapes that are before this feature label (before in history)
545 DocumentPtr aMyDoc = owner()->document();
546 std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures = aMyDoc->allFeatures();
547 std::list<std::shared_ptr<ModelAPI_Feature> >::iterator aFIter = allFeatures.begin();
548 bool aMePassed = false;
549 CompositeFeaturePtr aComposite =
550 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(owner());
551 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
552 CompositeFeaturePtr aCompositeOwner, aCompositeOwnerOwner;
553 if (aFeature.get()) {
554 aCompositeOwner = ModelAPI_Tools::compositeOwner(aFeature);
555 if (aCompositeOwner.get()) {
556 aCompositeOwnerOwner = ModelAPI_Tools::compositeOwner(aCompositeOwner);
559 // for group Scope is not limitet: this is always up to date objects
560 // this causes problem in galeries.py
561 //bool isGroup = aFeature.get() && aFeature->getKind() == "Group";
562 for(; aFIter != allFeatures.end(); aFIter++) {
563 if (*aFIter == owner()) { // the left features are created later (except subs of composite)
567 //if (isGroup) aMePassed = false;
568 bool isInScope = !aMePassed;
569 if (!isInScope && aComposite.get()) {
570 // try to add sub-elements of composite if this is composite
571 if (aComposite->isSub(*aFIter))
574 // remove the composite-owner of this feature (sketch in extrusion-cut)
575 if (isInScope && (aCompositeOwner == *aFIter || aCompositeOwnerOwner == *aFIter))
578 if (isInScope && aFIter->get() && (*aFIter)->data()->isValid()) {
579 TDF_Label aFeatureLab = std::dynamic_pointer_cast<Model_Data>(
580 (*aFIter)->data())->label().Father();
581 TDF_ChildIDIterator aNSIter(aFeatureLab, TNaming_NamedShape::GetID(), true);
582 for(; aNSIter.More(); aNSIter.Next()) {
583 Handle(TNaming_NamedShape) aNS = Handle(TNaming_NamedShape)::DownCast(aNSIter.Value());
584 if (!aNS.IsNull() && aNS->Evolution() != TNaming_SELECTED) {
585 myScope.Add(aNS->Label());
590 // also add all naming labels created for external constructions
591 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(aMyDoc);
592 TDF_Label anExtDocLab = aDoc->extConstructionsLabel();
593 TDF_ChildIDIterator aNSIter(anExtDocLab, TNaming_NamedShape::GetID(), true);
594 for(; aNSIter.More(); aNSIter.Next()) {
595 Handle(TNaming_NamedShape) aNS = Handle(TNaming_NamedShape)::DownCast(aNSIter.Value());
596 if (!aNS.IsNull() && aNS->Evolution() != TNaming_SELECTED) {
597 myScope.Add(aNS->Label());
604 /// Sets the invalid flag if flag is false, or removes it if "true"
606 static bool setInvalidIfFalse(TDF_Label& theLab, const bool theFlag) {
608 theLab.ForgetAttribute(kINVALID_SELECTION);
610 TDataStd_UAttribute::Set(theLab, kINVALID_SELECTION);
615 void Model_AttributeSelection::split(
616 ResultPtr theContext, TopoDS_Shape theNewShape, TopAbs_ShapeEnum theType)
618 TopTools_ListOfShape aSubs;
619 for(TopoDS_Iterator anExplorer(theNewShape); anExplorer.More(); anExplorer.Next()) {
620 if (!anExplorer.Value().IsNull() &&
621 anExplorer.Value().ShapeType() == theType) {
622 aSubs.Append(anExplorer.Value());
623 } else { // invalid case; bad result shape, so, impossible to split easily
628 if (aSubs.Extent() > 1) { // ok to split
629 TopTools_ListIteratorOfListOfShape aSub(aSubs);
630 GeomShapePtr aSubSh(new GeomAPI_Shape);
631 aSubSh->setImpl(new TopoDS_Shape(aSub.Value()));
632 setValue(theContext, aSubSh);
633 for(aSub.Next(); aSub.More(); aSub.Next()) {
634 GeomShapePtr aSubSh(new GeomAPI_Shape);
635 aSubSh->setImpl(new TopoDS_Shape(aSub.Value()));
636 myParent->append(theContext, aSubSh);
641 bool Model_AttributeSelection::update()
643 FeaturePtr aContextFeature = contextFeature();
644 if (aContextFeature.get()) {
647 TDF_Label aSelLab = selectionLabel();
648 ResultPtr aContext = context();
650 return setInvalidIfFalse(aSelLab, false);
651 if (aSelLab.IsAttribute(kSIMPLE_REF_ID)) { // it is just reference to shape, not sub-shape
652 return setInvalidIfFalse(aSelLab, aContext->shape() && !aContext->shape()->isNull());
655 if (aSelLab.IsAttribute(kPART_REF_ID)) { // it is reference to the part object
656 std::shared_ptr<GeomAPI_Shape> aNoSelection;
657 bool aResult = selectPart(aContext, aNoSelection, true);
658 aResult = setInvalidIfFalse(aSelLab, aResult);
660 owner()->data()->sendAttributeUpdated(this);
665 if (aContext->groupName() == ModelAPI_ResultBody::group()) {
666 if (aSelLab.IsAttribute(kWEAK_NAMING)) { // a weak naming is used
667 Handle(TDataStd_Integer) aWeakId;
668 aSelLab.FindAttribute(kWEAK_NAMING, aWeakId);
669 // get the context shape
670 GeomShapePtr aContextShape;
671 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
673 aContextShape = aBody->shape();
675 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
677 aContextShape = aResult->shape();
680 if (!setInvalidIfFalse(aSelLab, aContextShape.get() != NULL)) // context shape not found
682 Handle(TDataStd_Integer) aWeakShapeType;
683 aSelLab.FindAttribute(kWEAK_NAMING_SHAPETYPE, aWeakShapeType);
684 GeomAlgoAPI_NExplode aNExplode(
685 aContextShape, GeomAPI_Shape::ShapeType(aWeakShapeType->Get()));
686 GeomShapePtr aValue = aNExplode.shape(aWeakId->Get());
687 return setInvalidIfFalse(aSelLab, aValue.get() != NULL);
689 // body: just a named shape, use selection mechanism from OCCT
690 TNaming_Selector aSelector(aSelLab);
691 TopoDS_Shape anOldShape;
692 if (!aSelector.NamedShape().IsNull()) {
693 anOldShape = aSelector.NamedShape()->Get();
695 bool aResult = aSelector.Solve(scope()) == Standard_True;
696 // must be before sending of updated attribute (1556)
697 aResult = setInvalidIfFalse(aSelLab, aResult);
698 TopoDS_Shape aNewShape;
699 if (!aSelector.NamedShape().IsNull()) {
700 aNewShape = aSelector.NamedShape()->Get();
702 if (anOldShape.IsNull() || aNewShape.IsNull() ||
703 !anOldShape.IsEqual(aSelector.NamedShape()->Get())) {
704 // shape type shoud not not changed: if shape becomes compound of such shapes, then split
705 if (myParent && !anOldShape.IsNull() && !aNewShape.IsNull() &&
706 anOldShape.ShapeType() != aNewShape.ShapeType() &&
707 (aNewShape.ShapeType() == TopAbs_COMPOUND || aNewShape.ShapeType() == TopAbs_COMPSOLID))
709 split(aContext, aNewShape, anOldShape.ShapeType());
711 owner()->data()->sendAttributeUpdated(this); // send updated if shape is changed
716 if (aContext->groupName() == ModelAPI_ResultConstruction::group()) {
717 Handle(TDataStd_Integer) anIndex;
718 if (aSelLab.FindAttribute(TDataStd_Integer::GetID(), anIndex)) {
719 std::shared_ptr<Model_ResultConstruction> aConstructionContext =
720 std::dynamic_pointer_cast<Model_ResultConstruction>(aContext);
721 bool aModified = true;
722 bool aValid = aConstructionContext->update(anIndex->Get(), owner()->document(), aModified);
723 setInvalidIfFalse(aSelLab, aValid);
724 if (aConstructionContext->isInfinite()) {
725 // Update the selected shape.
726 TNaming_Builder aBuilder(aSelLab);
727 aBuilder.Generated(aConstructionContext->shape()->impl<TopoDS_Shape>());
730 owner()->data()->sendAttributeUpdated(this);
734 return setInvalidIfFalse(aSelLab, false); // unknown case
737 void Model_AttributeSelection::selectBody(
738 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
740 // perform the selection
741 TNaming_Selector aSel(selectionLabel());
742 TopoDS_Shape aContext;
744 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theContext);//myRef.value()
746 aContext = aBody->shape()->impl<TopoDS_Shape>();
749 std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
751 aContext = aResult->shape()->impl<TopoDS_Shape>();
753 Events_InfoMessage("Model_AttributeSelection", "A result with shape is expected").send();
758 // with "recover" feature the selected context may be not up to date (issue 1710)
759 Handle(TNaming_NamedShape) aResult;
760 TDF_Label aSelLab = selectionLabel();
761 TopoDS_Shape aNewContext = aContext;
762 bool isUpdated = true;
763 while(!aNewContext.IsNull() && isUpdated) {
764 // searching for the very last shape that was produced from this one
766 if (!TNaming_Tool::HasLabel(aSelLab, aNewContext))
767 // to avoid crash of TNaming_SameShapeIterator if pure shape does not exists
769 for(TNaming_SameShapeIterator anIter(aNewContext, aSelLab); anIter.More(); anIter.Next()) {
770 TDF_Label aNSLab = anIter.Label();
771 if (!scope().Contains(aNSLab))
773 Handle(TNaming_NamedShape) aNS;
774 if (aNSLab.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
775 for(TNaming_Iterator aShapesIter(aNS); aShapesIter.More(); aShapesIter.Next()) {
776 if (aShapesIter.Evolution() == TNaming_SELECTED)
777 continue; // don't use the selection evolution
778 if (!aShapesIter.OldShape().IsNull() && aShapesIter.OldShape().IsSame(aNewContext)) {
779 // found the original shape
780 aNewContext = aShapesIter.NewShape(); // go to the newer shape
788 if (aNewContext.IsNull()) { // a context is already deleted
789 setInvalidIfFalse(aSelLab, false);
790 Events_InfoMessage("Model_AttributeSelection", "Failed to select shape already deleted").send();
794 TopoDS_Shape aNewSub = theSubShape ? theSubShape->impl<TopoDS_Shape>() : aContext;
795 if (!aNewSub.IsEqual(aContext)) { // searching for subshape in the new context
796 bool isFound = false;
797 TopExp_Explorer anExp(aNewContext, aNewSub.ShapeType());
798 for(; anExp.More(); anExp.Next()) {
799 if (anExp.Current().IsSame(aNewSub)) {
804 if (!isFound) { // sub-shape is not found in the up-to-date instance of the context shape
805 // if context is sub-result of compound/compsolid, selection of sub-shape better propagate to
806 // the main result (which is may be modified); the case is in 1799
807 ResultBodyPtr aMain = ModelAPI_Tools::bodyOwner(theContext);
808 while(ModelAPI_Tools::bodyOwner(aMain).get())
809 aMain = ModelAPI_Tools::bodyOwner(theContext);
811 selectBody(aMain, theSubShape);
814 setInvalidIfFalse(aSelLab, false);
815 Events_InfoMessage("Model_AttributeSelection",
816 "Failed to select sub-shape already modified").send();
821 /// fix for issue 411: result modified shapes must not participate in this selection mechanism
822 if (!aContext.IsNull()) {
823 FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
824 bool aEraseResults = false;
825 if (aFeatureOwner.get()) {
826 aEraseResults = !aFeatureOwner->results().empty();
827 if (aEraseResults) // erase results without flash deleted and redisplay: do it after Select
828 aFeatureOwner->removeResults(0, false, false);
830 bool aSelectorOk = true;
832 aSel.Select(aNewSub, aNewContext);
836 // face may become divided after the model update, so, new labels may be added to the scope
839 // check that selection is correct, otherwise use weak naming solution
840 TDF_Label aSelLab = selectionLabel();
841 aSelLab.ForgetAttribute(kWEAK_NAMING);
842 Handle(TNaming_NamedShape) aSelectorShape;
843 if (aSelectorOk && aSelLab.FindAttribute(TNaming_NamedShape::GetID(), aSelectorShape))
845 TopoDS_Shape aShape = aSelectorShape->Get();
846 if (aShape.IsNull() || aShape.ShapeType() != aNewSub.ShapeType())
849 if (!aSelectorOk) { // weak naming identifier instead
850 GeomShapePtr aContextShape(new GeomAPI_Shape);
851 aContextShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aNewContext));
852 GeomShapePtr aValueShape(new GeomAPI_Shape);
853 aValueShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aNewSub));
855 GeomAlgoAPI_NExplode aNExplode(aContextShape, aValueShape->shapeType());
856 int anId = aNExplode.index(aValueShape);
858 TDataStd_Integer::Set(aSelLab, kWEAK_NAMING, anId);
859 TDataStd_Integer::Set(aSelLab, kWEAK_NAMING_SHAPETYPE, int(aValueShape->shapeType()));
863 if (aEraseResults) { // flash after Select : in Groups it makes selection with shift working
864 static Events_Loop* aLoop = Events_Loop::loop();
865 static const Events_ID kDeletedEvent = aLoop->eventByName(EVENT_OBJECT_DELETED);
866 aLoop->flush(kDeletedEvent);
871 bool Model_AttributeSelection::selectPart(
872 const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
873 const bool theUpdate)
875 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theContext);
876 if (!aPart.get() || !aPart->isActivated())
877 return true; // postponed naming
879 Handle(TDataStd_Integer) anIndex;
880 if (selectionLabel().FindAttribute(TDataStd_Integer::GetID(), anIndex)) {
881 // by internal selection
882 if (anIndex->Get() > 0) {
883 // update the selection by index
884 return aPart->updateInPart(anIndex->Get());
886 return true; // nothing to do, referencing just by name
889 return true; // nothing to do, referencing just by name
891 // store the shape (in case part is not loaded it should be useful
893 std::string aName = theContext->data()->name();
894 if (!theSubShape.get() || theSubShape->isNull()) {// the whole part shape is selected
895 aShape = theContext->shape()->impl<TopoDS_Shape>();
897 aShape = theSubShape->impl<TopoDS_Shape>();
899 aName += "/" + aPart->nameInPart(theSubShape, anIndex);
900 TDataStd_Integer::Set(selectionLabel(), anIndex);
902 TNaming_Builder aBuilder(selectionLabel());
903 aBuilder.Select(aShape, aShape);
904 // identify by name in the part
905 TDataStd_Name::Set(selectionLabel(), aName.c_str());
906 return !aName.empty();
909 TDF_Label Model_AttributeSelection::selectionLabel()
911 return myRef.myRef->Label().FindChild(1);
914 /// prefixes of the shape names with centers defined
915 static std::map<ModelAPI_AttributeSelection::CenterType, std::string> kCENTERS_PREFIX;
917 /// returns the map that contains all possible prefixes of the center-names
918 static std::map<ModelAPI_AttributeSelection::CenterType, std::string>& centersMap()
920 if (kCENTERS_PREFIX.empty()) { // fill map by initial values
921 kCENTERS_PREFIX[ModelAPI_AttributeSelection::CIRCLE_CENTER] = "__cc";
922 kCENTERS_PREFIX[ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS] = "__eff";
923 kCENTERS_PREFIX[ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS] = "__esf";
925 return kCENTERS_PREFIX;
928 std::string Model_AttributeSelection::namingName(const std::string& theDefaultName)
930 std::string aName("");
931 if(!this->isInitialized())
932 return !theDefaultName.empty() ? theDefaultName : aName;
934 CenterType aCenterType = NOT_CENTER;
935 std::shared_ptr<GeomAPI_Shape> aSubSh = internalValue(aCenterType);
936 ResultPtr aCont = context();
939 (aCont->groupName() == ModelAPI_ResultConstruction::group() && contextFeature().get())) {
940 // selection of a full feature
941 FeaturePtr aFeatureCont = contextFeature();
942 if (aFeatureCont.get()) {
943 return kWHOLE_FEATURE + aFeatureCont->name();
945 // in case of selection of removed result
949 TDF_Label aSelLab = selectionLabel();
950 Handle(TDataStd_Integer) aWeakId;
951 if (aSelLab.FindAttribute(kWEAK_NAMING, aWeakId)) { // a weak naming is used
952 std::ostringstream aNameStream;
953 aNameStream<<aCont->data()->name()<<"/weak_name_"<<aWeakId->Get();
954 return aNameStream.str();
957 Model_SelectionNaming aSelNaming(aSelLab);
958 std::string aResult = aSelNaming.namingName(
959 aCont, aSubSh, theDefaultName, owner()->document() != aCont->document());
960 if (aCenterType != NOT_CENTER) {
961 aResult += centersMap()[aCenterType];
966 // returns the center type and modifies the shape name if this name is center-name
967 static ModelAPI_AttributeSelection::CenterType centerTypeByName(std::string& theShapeName)
969 std::map<ModelAPI_AttributeSelection::CenterType, std::string>::iterator aPrefixIter =
970 centersMap().begin();
971 for(; aPrefixIter != centersMap().end(); aPrefixIter++) {
972 std::size_t aFound = theShapeName.find(aPrefixIter->second);
973 if (aFound != std::string::npos &&
974 aFound == theShapeName.size() - aPrefixIter->second.size()) {
975 theShapeName = theShapeName.substr(0, aFound);
976 return aPrefixIter->first;
979 return ModelAPI_AttributeSelection::NOT_CENTER;
982 // type ::= COMP | COMS | SOLD | SHEL | FACE | WIRE | EDGE | VERT
983 void Model_AttributeSelection::selectSubShape(
984 const std::string& theType, const std::string& theSubShapeName)
986 if(theSubShapeName.empty() || theType.empty()) return;
988 std::string aSubShapeName = theSubShapeName;
989 CenterType aCenterType = theType[0] == 'v' || theType[0] == 'V' ? // only for vertex-type
990 centerTypeByName(aSubShapeName) : NOT_CENTER;
991 std::string aType = aCenterType == NOT_CENTER ? theType : "EDGE"; // search for edge now
993 // first iteration is selection by name without center prefix, second - in case of problem,
994 // try with initial name
995 for(int aUseCenter = 1; aUseCenter >= 0; aUseCenter--) {
996 if (aUseCenter == 0 && aCenterType != NOT_CENTER) {
997 aSubShapeName = theSubShapeName;
998 aCenterType = NOT_CENTER;
1000 } else if (aUseCenter != 1) continue;
1002 // check this is Part-name: 2 delimiters in the name
1003 std::size_t aPartEnd = aSubShapeName.find('/');
1004 if (aPartEnd != std::string::npos && aPartEnd != aSubShapeName.rfind('/')) {
1005 std::string aPartName = aSubShapeName.substr(0, aPartEnd);
1006 ObjectPtr aFound = owner()->document()->objectByName(ModelAPI_ResultPart::group(), aPartName);
1007 if (aFound.get()) { // found such part, so asking it for the name
1008 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFound);
1009 std::string aNameInPart = aSubShapeName.substr(aPartEnd + 1);
1011 std::shared_ptr<GeomAPI_Shape> aSelected = aPart->shapeInPart(aNameInPart, aType, anIndex);
1012 if (aSelected.get()) {
1013 if (aCenterType != NOT_CENTER) {
1014 if (!aSelected->isEdge())
1016 std::shared_ptr<GeomAPI_Edge> aSelectedEdge(new GeomAPI_Edge(aSelected));
1017 setValueCenter(aPart, aSelectedEdge, aCenterType);
1019 setValue(aPart, aSelected);
1020 TDataStd_Integer::Set(selectionLabel(), anIndex);
1026 std::shared_ptr<Model_Document> aDoc =
1027 std::dynamic_pointer_cast<Model_Document>(owner()->document());
1028 // check this is a whole feature context
1029 if (aSubShapeName.size() > kWHOLE_FEATURE.size() &&
1030 aSubShapeName.substr(0, kWHOLE_FEATURE.size()) == kWHOLE_FEATURE) {
1031 std::string aFeatureName = aSubShapeName.substr(kWHOLE_FEATURE.size());
1032 ObjectPtr anObj = aDoc->objectByName(ModelAPI_Feature::group(), aFeatureName);
1034 static const GeomShapePtr anEmptyShape;
1035 setValue(anObj, anEmptyShape);
1040 Model_SelectionNaming aSelNaming(selectionLabel());
1041 std::shared_ptr<GeomAPI_Shape> aShapeToBeSelected;
1043 if (aSelNaming.selectSubShape(aType, aSubShapeName, aDoc, aShapeToBeSelected, aCont)) {
1044 // try to find the last context to find the up to date shape
1045 if (aCont->shape().get() && !aCont->shape()->isNull() &&
1046 aCont->groupName() == ModelAPI_ResultBody::group() && aDoc == owner()->document()) {
1047 const TopoDS_Shape aConShape = aCont->shape()->impl<TopoDS_Shape>();
1048 if (!aConShape.IsNull()) {
1049 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aConShape, selectionLabel());
1050 if (!aNS.IsNull()) {
1051 aNS = TNaming_Tool::CurrentNamedShape(aNS);
1052 if (!aNS.IsNull() && scope().Contains(aNS->Label())) { // scope check is for 2228
1053 TDF_Label aLab = aNS->Label();
1054 if (aLab.Depth() % 2 == 0)
1055 aLab = aLab.Father();
1056 ObjectPtr anObj = aDoc->objects()->object(aLab);
1057 while(!anObj.get() && aLab.Depth() > 5) {
1058 aLab = aLab.Father().Father();
1059 anObj = aDoc->objects()->object(aLab);
1063 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1071 // if compsolid is context, try to take sub-solid as context: like in GUI and scripts
1072 if (aCont.get() && aShapeToBeSelected.get()) {
1073 ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aCont);
1074 if (aComp && aComp->numberOfSubs()) {
1075 std::list<ResultPtr> allSubs;
1076 ModelAPI_Tools::allSubs(aComp, allSubs);
1077 std::list<ResultPtr>::iterator aS = allSubs.begin();
1078 for(; aS != allSubs.end(); aS++) {
1079 ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aS);
1080 if (aSub && aSub->numberOfSubs() == 0 && aSub->shape().get() &&
1081 aSub->shape()->isSubShape(aShapeToBeSelected)) {
1088 // try to find the latest active result that must be used instead of the selected
1089 // to set the active context (like in GUI selection), not concealed one
1090 bool aFindNewContext = true;
1091 while(aFindNewContext && aCont.get()) {
1092 aFindNewContext = false;
1093 // take references to all results: root one, any sub
1094 ResultBodyPtr aCompContext = ModelAPI_Tools::bodyOwner(aCont, true);
1095 std::list<ResultPtr> allRes;
1096 if (aCompContext.get()) {
1097 ModelAPI_Tools::allSubs(aCompContext, allRes);
1098 allRes.push_back(aCompContext);
1100 allRes.push_back(aCont);
1102 for(std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
1103 ResultPtr aResCont = *aSub;
1104 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont);
1105 // only lower and higher level subs are counted
1106 if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext)
1108 const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
1109 std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
1110 for(; !aFindNewContext && aRef != aRefs.end(); aRef++) {
1111 if (!aRef->get() || !(*aRef)->owner().get())
1113 // concealed attribute only
1114 FeaturePtr aRefFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
1115 if (!ModelAPI_Session::get()->validators()->isConcealed(
1116 aRefFeat->getKind(), (*aRef)->id()))
1118 // search the feature result that contains sub-shape selected
1119 std::list<std::shared_ptr<ModelAPI_Result> > aResults;
1121 // take all sub-results or one result
1122 std::list<ResultPtr> aRefFeatResults;
1123 ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults);
1124 std::list<ResultPtr>::iterator aRefResIter = aRefFeatResults.begin();
1125 for(; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
1126 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRefResIter);
1127 if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
1128 aResults.push_back(aBody);
1130 std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
1131 for(; aResIter != aResults.end(); aResIter++) {
1132 if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
1134 GeomShapePtr aShape = (*aResIter)->shape();
1135 GeomShapePtr aSelectedShape =
1136 aShapeToBeSelected.get() ? aShapeToBeSelected : aCont->shape();
1137 if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) {
1138 aCont = *aResIter; // found new context (produced from this) with same subshape
1139 aFindNewContext = true; // continue searching futher
1147 if (aCenterType != NOT_CENTER) {
1148 if (!aShapeToBeSelected->isEdge())
1150 std::shared_ptr<GeomAPI_Edge> aSelectedEdge(new GeomAPI_Edge(aShapeToBeSelected));
1151 setValueCenter(aCont, aSelectedEdge, aCenterType);
1153 setValue(aCont, aShapeToBeSelected);
1158 TDF_Label aSelLab = selectionLabel();
1159 setInvalidIfFalse(aSelLab, false);
1163 void Model_AttributeSelection::selectSubShape(const std::string& theType,
1164 const GeomPointPtr& thePoint)
1166 if (theType.empty() || !thePoint)
1169 // list of parent features
1170 FeaturePtr anOwner = ModelAPI_Feature::feature(owner());
1171 std::set<FeaturePtr> aParents = ModelAPI_Tools::getParents(anOwner);
1173 int aSelectionIndex = 0;
1174 GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(theType);
1175 if (aType == GeomAPI_Shape::SHAPE) {
1176 // possibly, the string consists of the type and the index,
1177 // thus, try to separate them
1178 size_t aUndersporePos = theType.find_first_of('_');
1179 if (aUndersporePos != std::string::npos)
1180 aType = GeomAPI_Shape::shapeTypeByStr(theType.substr(0, aUndersporePos));
1182 if (aType != GeomAPI_Shape::SHAPE) {
1183 for (std::string::const_iterator aChar = theType.begin() + aUndersporePos + 1;
1184 aChar != theType.end(); ++aChar) {
1185 if (std::isdigit(*aChar))
1186 aSelectionIndex = aSelectionIndex * 10 + (*aChar - '0');
1188 aSelectionIndex = 1;
1192 aSelectionIndex -= 1;
1196 std::list<ModelGeomAlgo_Shape::SubshapeOfResult> anAppropriate;
1198 // collect features from PartSet and the current part
1199 SessionPtr aSession = ModelAPI_Session::get();
1200 std::list<FeaturePtr> aFeatures = aSession->moduleDocument()->allFeatures();
1201 if (aSession->moduleDocument() != owner()->document()) {
1202 std::list<FeaturePtr> aPartFeatures = owner()->document()->allFeatures();
1203 aFeatures.insert(aFeatures.end(), aPartFeatures.begin(), aPartFeatures.end());
1205 // Process results of all features from the last to the first
1206 // to find appropriate sub-shape
1207 for (std::list<FeaturePtr>::const_reverse_iterator anIt = aFeatures.rbegin();
1208 anIt != aFeatures.rend(); ++anIt) {
1209 // selection cannot be linked to the parent features
1210 if (aParents.find(*anIt) != aParents.end())
1212 // check the feature is a part of composite feature (like sketch elements),
1213 // then do not process it, it will be processed in scope of composite feature
1214 bool isSubOfComposite = false;
1215 const std::set<AttributePtr>& aRefs = (*anIt)->data()->refsToMe();
1216 for (std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin();
1217 aRefIt != aRefs.end() && !isSubOfComposite; ++aRefIt) {
1218 FeaturePtr aFeature = ModelAPI_Feature::feature((*aRefIt)->owner());
1219 CompositeFeaturePtr aCompFeature =
1220 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
1221 isSubOfComposite = aCompFeature && aCompFeature->isSub(*anIt);
1223 if (isSubOfComposite)
1226 // process results of the current feature to find appropriate sub-shape
1227 if (ModelGeomAlgo_Shape::findSubshapeByPoint(*anIt, thePoint, aType, anAppropriate)) {
1228 std::list<ModelGeomAlgo_Shape::SubshapeOfResult>::iterator anApIt = anAppropriate.begin();
1229 for (; aSelectionIndex > 0 && anApIt != anAppropriate.end(); --aSelectionIndex)
1230 ++anApIt; // skip this shape, because one of the previous is selected
1232 if (anApIt != anAppropriate.end()) {
1233 if (anApIt->myCenterType == (int)ModelAPI_AttributeSelection::NOT_CENTER)
1234 setValue(anApIt->myResult, anApIt->mySubshape);
1236 setValueCenter(anApIt->myResult, anApIt->mySubshape->edge(),
1237 (ModelAPI_AttributeSelection::CenterType)anApIt->myCenterType);
1243 TDF_Label aSelLab = selectionLabel();
1244 setInvalidIfFalse(aSelLab, false);
1248 void Model_AttributeSelection::selectSubShape(const std::string& theType,
1249 const std::string& theContextName, const int theIndex)
1251 // selection of context by name
1252 //std::string aNamingContextName = theContextName + "/";
1253 //selectSubShape(theType, aNamingContextName);
1254 std::shared_ptr<Model_Document> aDoc =
1255 std::dynamic_pointer_cast<Model_Document>(owner()->document());
1257 bool aUnique = true;
1258 std::string aContextName = theContextName;
1259 std::string anEmptySub = "";
1260 ResultPtr aContext = aDoc->findByName(aContextName, anEmptySub, aUnique);
1261 //ResultPtr aContext = context();
1262 if (aContext.get()) {
1263 GeomShapePtr aContShape = aContext->shape();
1264 if (aContShape.get()) {
1265 GeomAlgoAPI_NExplode aNExp(aContShape, GeomAPI_Shape::shapeTypeByStr(theType));
1266 GeomShapePtr aValue = aNExp.shape(theIndex);
1268 setValue(aContext, aValue);
1274 int Model_AttributeSelection::Id()
1277 std::shared_ptr<GeomAPI_Shape> aSelection = value();
1278 ResultPtr aContextRes = context();
1279 // support for compsolids:
1280 while(ModelAPI_Tools::bodyOwner(aContextRes).get()) {
1281 aContextRes = ModelAPI_Tools::bodyOwner(aContextRes);
1283 std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
1286 TopoDS_Shape aMainShape = aContext->impl<TopoDS_Shape>();
1287 const TopoDS_Shape& aSubShape = aSelection->impl<TopoDS_Shape>();
1288 // searching for the latest main shape
1289 if (aSelection && !aSelection->isNull() && aContext && !aContext->isNull())
1291 std::shared_ptr<Model_Document> aDoc =
1292 std::dynamic_pointer_cast<Model_Document>(context()->document());
1294 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel());
1295 if (!aNS.IsNull()) {
1296 aMainShape = TNaming_Tool::CurrentShape(aNS);
1300 TopTools_IndexedMapOfShape aSubShapesMap;
1301 TopExp::MapShapes(aMainShape, aSubShapesMap);
1302 anID = aSubShapesMap.FindIndex(aSubShape);
1307 void Model_AttributeSelection::setId(int theID)
1309 std::shared_ptr<GeomAPI_Shape> aSelection;
1311 ResultPtr aContextRes = context();
1312 // support for compsolids:
1313 while(ModelAPI_Tools::bodyOwner(aContextRes).get()) {
1314 aContextRes = ModelAPI_Tools::bodyOwner(aContextRes);
1316 std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
1318 TopoDS_Shape aMainShape = aContext->impl<TopoDS_Shape>();
1319 // searching for the latest main shape
1320 if (theID > 0 && aContext && !aContext->isNull())
1322 std::shared_ptr<Model_Document> aDoc =
1323 std::dynamic_pointer_cast<Model_Document>(aContextRes->document());
1325 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel());
1326 if (!aNS.IsNull()) {
1327 aMainShape = TNaming_Tool::CurrentShape(aNS);
1331 TopTools_IndexedMapOfShape aSubShapesMap;
1332 TopExp::MapShapes(aMainShape, aSubShapesMap);
1333 const TopoDS_Shape& aSelShape = aSubShapesMap.FindKey(theID);
1335 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
1336 aResult->setImpl(new TopoDS_Shape(aSelShape));
1338 aSelection = aResult;
1341 setValue(aContextRes, aSelection);
1344 std::string Model_AttributeSelection::contextName(const ResultPtr& theContext) const
1346 std::string aResult;
1347 if (owner()->document() != theContext->document()) {
1348 if (theContext->document() == ModelAPI_Session::get()->moduleDocument()) {
1349 aResult = theContext->document()->kind() + "/";
1351 ResultPtr aDocRes = ModelAPI_Tools::findPartResult(
1352 ModelAPI_Session::get()->moduleDocument(), theContext->document());
1353 if (aDocRes.get()) {
1354 aResult = aDocRes->data()->name() + "/";
1358 aResult += theContext->data()->name();
1362 void Model_AttributeSelection::computeValues(
1363 ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape,
1364 TopTools_ListOfShape& theShapes)
1366 bool aWasWholeContext = theValShape.IsNull();
1367 if (aWasWholeContext) {
1368 //theShapes.Append(theValShape);
1370 theValShape = theOldContext->shape()->impl<TopoDS_Shape>();
1372 //TopoDS_Shape anOldContShape = theOldContext->shape()->impl<TopoDS_Shape>();
1373 TopoDS_Shape aNewContShape = theNewContext->shape()->impl<TopoDS_Shape>();
1374 //if (anOldContShape.IsSame(theValShape)) { // full context shape substituted by new full context
1375 //theShapes.Append(aNewContShape);
1378 // if a new value is unchanged in the new context, do nothing: value is correct
1379 TopExp_Explorer aSubExp(aNewContShape, theValShape.ShapeType());
1380 for(; aSubExp.More(); aSubExp.Next()) {
1381 if (aSubExp.Current().IsSame(theValShape)) {
1382 theShapes.Append(theValShape);
1386 // if new context becomes compsolid, the resulting sub may be in sub-solids
1387 std::list<ResultPtr> aNewToIterate;
1388 aNewToIterate.push_back(theNewContext);
1389 ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theNewContext);
1391 std::list<ResultPtr> allNewContextSubs;
1392 ModelAPI_Tools::allSubs(aComp, allNewContextSubs);
1393 std::list<ResultPtr>::iterator aSub = allNewContextSubs.begin();
1394 for(; aSub != allNewContextSubs.end(); aSub++) {
1395 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSub);
1396 if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
1397 aNewToIterate.push_back(aBody);
1401 // first iteration: searching for the whole shape appearance (like face of the box)
1402 // second iteration: searching for sub-shapes that contain the sub (like vertex on faces)
1403 int aToFindPart = 0;
1404 TopTools_DataMapOfShapeShape aNewToOld; // map from new containers to old containers (with val)
1405 TopTools_MapOfShape anOlds; // to know how many olds produced new containers
1406 for(; aToFindPart != 2 && theShapes.IsEmpty(); aToFindPart++) {
1407 std::list<ResultPtr>::iterator aNewContIter = aNewToIterate.begin();
1408 for(; aNewContIter != aNewToIterate.end(); aNewContIter++) {
1409 std::shared_ptr<Model_Data> aNewData =
1410 std::dynamic_pointer_cast<Model_Data>((*aNewContIter)->data());
1411 TDF_Label aNewLab = aNewData->label();
1412 // searching for produced sub-shape fully on some label
1413 TDF_ChildIDIterator aNSIter(aNewLab, TNaming_NamedShape::GetID(), Standard_True);
1414 for(; aNSIter.More(); aNSIter.Next()) {
1415 Handle(TNaming_NamedShape) aNS = Handle(TNaming_NamedShape)::DownCast(aNSIter.Value());
1416 for(TNaming_Iterator aPairIter(aNS); aPairIter.More(); aPairIter.Next()) {
1417 if (aToFindPart == 0) { // search shape is fully inside
1418 if (aPairIter.OldShape().IsSame(theValShape)) {
1419 if (aPairIter.NewShape().IsNull()) {// value was removed
1423 theShapes.Append(aPairIter.NewShape());
1425 } else if (!aPairIter.OldShape().IsNull()) { // search shape that contains this sub
1426 TopExp_Explorer anExp(aPairIter.OldShape(), theValShape.ShapeType());
1427 for(; anExp.More(); anExp.Next()) {
1428 if (anExp.Current().IsSame(theValShape)) { // found a new container
1429 if (aPairIter.NewShape().IsNull()) {// value was removed
1433 aNewToOld.Bind(aPairIter.NewShape(), aPairIter.OldShape());
1434 anOlds.Add(aPairIter.OldShape());
1443 if (aToFindPart == 2 && !aNewToOld.IsEmpty()) {
1444 // map of sub-shapes -> number of occurences of these shapes in containers
1445 NCollection_DataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> aSubs;
1446 TopTools_DataMapOfShapeShape::Iterator aContIter(aNewToOld);
1447 for(; aContIter.More(); aContIter.Next()) {
1448 TopExp_Explorer aSubExp(aContIter.Key(), theValShape.ShapeType());
1449 for(; aSubExp.More(); aSubExp.Next()) {
1450 if (!aSubs.IsBound(aSubExp.Current())) {
1451 aSubs.Bind(aSubExp.Current(), TopTools_MapOfShape());
1453 // store old to know how many olds produced this shape
1454 aSubs.ChangeFind(aSubExp.Current()).Add(aContIter.Value());
1457 // if sub is appeared same times in containers as the number of old shapes that contain it
1458 int aCountInOld = anOlds.Size();
1459 NCollection_DataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>::Iterator
1461 for(; aSubsIter.More(); aSubsIter.Next()) {
1462 if (aSubsIter.Value().Size() == aCountInOld) {
1463 theShapes.Append(aSubsIter.Key());
1467 if (theShapes.IsEmpty()) { // nothing was changed
1468 theShapes.Append(aWasWholeContext ? TopoDS_Shape() : theValShape);
1472 bool Model_AttributeSelection::searchNewContext(std::shared_ptr<Model_Document> theDoc,
1473 const TopoDS_Shape theContShape, ResultPtr theContext, TopoDS_Shape theValShape,
1474 TDF_Label theAccessLabel,
1475 std::list<ResultPtr>& theResults, TopTools_ListOfShape& theValShapes)
1477 std::set<ResultPtr> aResults; // to avoid duplicates, new context, null if deleted
1478 TopTools_ListOfShape aResContShapes;
1479 // iterate context and shape, but also if it is sub-shape of main shape, check also it
1480 TopTools_ListOfShape aContextList;
1481 aContextList.Append(theContShape);
1482 if (theContext.get()) {
1483 ResultPtr aComposite = ModelAPI_Tools::bodyOwner(theContext);
1484 if (aComposite.get() && aComposite->shape().get() && !aComposite->shape()->isNull())
1485 aContextList.Append(aComposite->shape()->impl<TopoDS_Shape>());
1487 for(TopTools_ListOfShape::Iterator aContIter(aContextList); aContIter.More(); aContIter.Next()) {
1488 TNaming_SameShapeIterator aModifIter(aContIter.ChangeValue(), theAccessLabel);
1489 for(; aModifIter.More(); aModifIter.Next()) {
1490 TDF_Label anObjLab = aModifIter.Label().Father();
1491 ResultPtr aModifierObj = std::dynamic_pointer_cast<ModelAPI_Result>
1492 (theDoc->objects()->object(anObjLab));
1493 if (!aModifierObj.get()) {
1494 // #2241: shape may be sub-element of new object, not main (shell created from faces)
1495 if (!anObjLab.IsRoot())
1496 aModifierObj = std::dynamic_pointer_cast<ModelAPI_Result>
1497 (theDoc->objects()->object(anObjLab.Father()));
1498 if (!aModifierObj.get())
1501 FeaturePtr aModifierFeat = theDoc->feature(aModifierObj);
1502 if (!aModifierFeat.get())
1504 FeaturePtr aThisFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
1505 if (aModifierFeat == aThisFeature || theDoc->objects()->isLater(aModifierFeat, aThisFeature))
1506 continue; // the modifier feature is later than this, so, should not be used
1507 FeaturePtr aCurrentModifierFeat = theDoc->feature(theContext);
1508 if (aCurrentModifierFeat == aModifierFeat ||
1509 theDoc->objects()->isLater(aCurrentModifierFeat, aModifierFeat))
1510 continue; // the current modifier is later than the found, so, useless
1511 Handle(TNaming_NamedShape) aNewNS;
1512 aModifIter.Label().FindAttribute(TNaming_NamedShape::GetID(), aNewNS);
1513 if (aNewNS->Evolution() == TNaming_MODIFY || aNewNS->Evolution() == TNaming_GENERATED) {
1514 aResults.insert(aModifierObj);
1515 //TNaming_Iterator aPairIter(aNewNS);
1516 //aResContShapes.Append(aPairIter.NewShape());
1517 aResContShapes.Append(aModifierObj->shape()->impl<TopoDS_Shape>());
1518 } else if (aNewNS->Evolution() == TNaming_DELETE) { // a shape was deleted => result is empty
1519 aResults.insert(ResultPtr());
1520 } else { // not-precessed modification => don't support it
1525 if (aResults.empty())
1526 return false; // no modifications found, must stay the same
1527 // iterate all results to find futher modifications
1528 std::set<ResultPtr>::iterator aResIter = aResults.begin();
1529 for(; aResIter != aResults.end(); aResIter++) {
1530 if (aResIter->get() != NULL) {
1531 // compute new values by two contextes: the old and the new
1532 TopTools_ListOfShape aValShapes;
1533 computeValues(theContext, *aResIter, theValShape, aValShapes);
1535 TopTools_ListIteratorOfListOfShape aNewVal(aValShapes);
1536 for(; aNewVal.More(); aNewVal.Next()) {
1537 std::list<ResultPtr> aNewRes;
1538 TopTools_ListOfShape aNewUpdatedVal;
1539 TopoDS_Shape aNewValSh = aNewVal.Value();
1540 TopoDS_Shape aNewContShape = (*aResIter)->shape()->impl<TopoDS_Shape>();
1541 if (theValShape.IsNull() && aNewContShape.IsSame(aNewValSh))
1542 aNewValSh.Nullify();
1543 if (searchNewContext(theDoc, aNewContShape, *aResIter, aNewValSh,
1544 theAccessLabel, aNewRes, aNewUpdatedVal))
1546 // appeand new results instead of the current ones
1547 std::list<ResultPtr>::iterator aNewIter = aNewRes.begin();
1548 TopTools_ListIteratorOfListOfShape aNewUpdVal(aNewUpdatedVal);
1549 for(; aNewIter != aNewRes.end(); aNewIter++, aNewUpdVal.Next()) {
1550 theResults.push_back(*aNewIter);
1551 theValShapes.Append(aNewUpdVal.Value());
1553 } else { // the current result is good
1554 theResults.push_back(*aResIter);
1555 theValShapes.Append(aNewValSh);
1560 return true; // theResults must be empty: everything is deleted
1563 void Model_AttributeSelection::updateInHistory()
1565 ResultPtr aContext = std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
1566 // only bodies and parts may be modified later in the history, don't do anything otherwise
1567 if (!aContext.get() || (aContext->groupName() != ModelAPI_ResultBody::group() &&
1568 aContext->groupName() != ModelAPI_ResultPart::group()))
1570 std::shared_ptr<Model_Document> aDoc =
1571 std::dynamic_pointer_cast<Model_Document>(aContext->document());
1572 std::shared_ptr<Model_Data> aContData = std::dynamic_pointer_cast<Model_Data>(aContext->data());
1573 if (!aContData.get() || !aContData->isValid())
1575 TDF_Label aContLab = aContData->label(); // named shape where the selected context is located
1576 Handle(TNaming_NamedShape) aContNS;
1577 if (!aContLab.FindAttribute(TNaming_NamedShape::GetID(), aContNS)) {
1578 bool aFoundNewContext = true;
1579 ResultPtr aNewContext = aContext;
1580 while(aFoundNewContext) {
1581 aFoundNewContext = false;
1582 // parts have no shape in result, so, trace references using the Part info
1583 if (aNewContext->groupName() == ModelAPI_ResultPart::group()) {
1584 ResultPartPtr aPartContext = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aNewContext);
1585 if (aPartContext.get()) { // searching for the up to date references to the referenced cont
1586 const std::set<AttributePtr>& aRefs = aPartContext->data()->refsToMe();
1587 std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
1588 for(; aRef != aRefs.end(); aRef++) {
1589 // to avoid detection of part changes by local selection only
1590 AttributeSelectionPtr aSel =
1591 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRef);
1592 if (aSel.get() && !aSel->value()->isSame(aSel->context()->shape()))
1595 FeaturePtr aRefFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
1596 if (aRefFeat.get() && aRefFeat != owner()) {
1597 FeaturePtr aThisFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
1598 if (aDoc->objects()->isLater(aThisFeature, aRefFeat)) { // found better feature
1599 aFoundNewContext = true;
1600 aNewContext = aRefFeat->firstResult();
1607 if (aNewContext != aContext) {
1608 setValue(aNewContext, value());
1612 FeaturePtr aThisFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
1613 FeaturePtr aCurrentModifierFeat = aDoc->feature(aContext);
1614 // iterate the context shape modifications in order to find a feature that is upper in history
1615 // that this one and is really modifies the referenced result to refer to it
1616 ResultPtr aModifierResFound;
1617 TNaming_Iterator aPairIter(aContNS);
1618 if (!aPairIter.More())
1620 TopoDS_Shape aNewCShape = aPairIter.NewShape();
1621 bool anIterate = true;
1622 // trying to update also the sub-shape selected
1623 GeomShapePtr aSubShape = value();
1624 if (aSubShape.get() && aSubShape->isEqual(aContext->shape()))
1626 TopoDS_Shape aValShape;
1627 if (aSubShape.get()) {
1628 aValShape = aSubShape->impl<TopoDS_Shape>();
1631 std::list<ResultPtr> aNewContexts;
1632 TopTools_ListOfShape aValShapes;
1633 if (searchNewContext(aDoc, aNewCShape, aContext, aValShape, aContLab, aNewContexts, aValShapes))
1635 // update scope to reset to a new one
1638 std::list<ResultPtr>::iterator aNewCont = aNewContexts.begin();
1639 TopTools_ListIteratorOfListOfShape aNewValues(aValShapes);
1640 if (aNewCont == aNewContexts.end()) { // all results were deleted
1641 ResultPtr anEmptyContext;
1642 std::shared_ptr<GeomAPI_Shape> anEmptyShape;
1643 setValue(anEmptyContext, anEmptyShape); // nullify the selection
1647 GeomShapePtr aValueShape;
1648 if (!aNewValues.Value().IsNull()) {
1649 aValueShape = std::make_shared<GeomAPI_Shape>();
1650 aValueShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aNewValues.Value()));
1652 setValue(*aNewCont, aValueShape);
1653 // if there are more than one result, put them by "append" into "parent" list
1655 for(aNewCont++, aNewValues.Next(); aNewCont != aNewContexts.end();
1656 aNewCont++, aNewValues.Next()) {
1657 GeomShapePtr aValueShape;
1658 if (!aNewValues.Value().IsNull()) {
1659 aValueShape = std::make_shared<GeomAPI_Shape>();
1660 aValueShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aNewValues.Value()));
1663 // Check that list has the same type of shape selection before adding.
1664 GeomAPI_Shape::ShapeType aListShapeType = GeomAPI_Shape::SHAPE;
1665 if (myParent->selectionType() == "VERTEX") aListShapeType = GeomAPI_Shape::VERTEX;
1666 else if (myParent->selectionType() == "EDGE") aListShapeType = GeomAPI_Shape::EDGE;
1667 else if (myParent->selectionType() == "FACE") aListShapeType = GeomAPI_Shape::FACE;
1669 GeomAPI_Shape::ShapeType aShapeShapeType = GeomAPI_Shape::SHAPE;
1670 if (aValueShape.get()) {
1671 aShapeShapeType = aValueShape->shapeType();
1673 (*aNewCont)->shape()->shapeType();
1676 if (aListShapeType != GeomAPI_Shape::SHAPE && aListShapeType != aShapeShapeType) {
1680 myParent->append(*aNewCont, aValueShape);
1686 void Model_AttributeSelection::setParent(Model_AttributeSelectionList* theParent)
1688 myParent = theParent;
1691 bool Model_AttributeSelection::isWeakNaming()
1693 return selectionLabel().IsAttribute(kWEAK_NAMING);