1 // Copyright (C) 2017-2022 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 email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_VersionedChFi.h"
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_Tools.h>
25 #include <GeomAlgoAPI_MakeShapeList.h>
27 #include <GeomAPI_ShapeExplorer.h>
30 static const std::string CHAMFERFILLET_VERSION_1("v9.5");
33 // Obtain all sub-shapes from the shape and append them to the list
34 static void collectSubs(const GeomShapePtr& theShape,
36 const GeomAPI_Shape::ShapeType theShapeType)
38 GeomAPI_ShapeExplorer anExp(theShape, theShapeType);
39 for (; anExp.more(); anExp.next()) {
40 GeomShapePtr aShape = anExp.current();
41 // Store all shapes with FORWARD orientation to avoid duplication of shared edges/vertices
42 aShape->setOrientation(GeomAPI_Shape::FORWARD);
43 theSubs.push_back(aShape);
48 void FeaturesPlugin_VersionedChFi::initVersion(const AttributePtr& theObjectsAttr)
50 if (!theObjectsAttr->isInitialized()) {
51 // new feature, not read from file
52 data()->setVersion(CHAMFERFILLET_VERSION_1);
56 void FeaturesPlugin_VersionedChFi::execute()
58 GeomAPI_ShapeHierarchy anObjectHierarchy;
59 if (!processAttribute(objectsAttribute(), anObjectHierarchy))
62 // Perform the operation
63 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList);
68 ListOfShape anOriginalSolids;
69 for (GeomAPI_ShapeHierarchy::iterator anIt = anObjectHierarchy.begin();
70 anIt != anObjectHierarchy.end(); ++anIt) {
71 GeomShapePtr aSolid = anObjectHierarchy.parent(*anIt);
72 const ListOfShape& aSubs = anObjectHierarchy.objects(aSolid);
74 std::shared_ptr<GeomAlgoAPI_MakeShape> anAlgo = performOperation(aSolid, aSubs);
76 return; // something gone wrong
78 anObjectHierarchy.markModified(aSolid, anAlgo->shape());
79 aMakeShapeList->appendAlgo(anAlgo);
81 anOriginalSolids.push_back(aSolid);
82 anEdges.insert(anEdges.end(), aSubs.begin(), aSubs.end());
85 // Build results of the operaion.
86 const std::string& aPrefix = modifiedShapePrefix();
87 ListOfShape aTopLevel;
88 anObjectHierarchy.topLevelObjects(aTopLevel);
89 for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt) {
90 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
91 ModelAPI_Tools::loadModifiedShapes(aResultBody, anOriginalSolids, ListOfShape(),
92 aMakeShapeList, *anIt, aPrefix);
93 setResult(aResultBody, aResultIndex++);
95 for (ListOfShape::iterator aEIt = anEdges.begin(); aEIt != anEdges.end(); ++aEIt) {
96 GeomShapePtr aBase = *aEIt;
97 // Store new faces generated from edges and vertices
98 aResultBody->loadGeneratedShapes(aMakeShapeList, aBase, GeomAPI_Shape::EDGE, aPrefix, true);
101 ModelAPI_Tools::loadDeletedShapes(aResultBody, GeomShapePtr(), anOriginalSolids,
102 aMakeShapeList, *anIt);
105 removeResults(aResultIndex);
109 bool FeaturesPlugin_VersionedChFi::processAttribute(const AttributePtr& theAttribute,
110 GeomAPI_ShapeHierarchy& theObjects)
112 bool isStoreFullHierarchy = data()->version() == CHAMFERFILLET_VERSION_1;
114 AttributeSelectionListPtr anObjectsSelList =
115 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
116 for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); ++anObjectsIndex) {
117 AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
118 GeomShapePtr anObject = anObjectAttr->value();
122 ResultPtr aContext = anObjectAttr->context();
123 GeomShapePtr aParent;
124 if (aContext.get()) {
125 ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext);
126 if (aCtxOwner && aCtxOwner->shape()->shapeType() == GeomAPI_Shape::COMPSOLID)
127 aContext = aCtxOwner;
128 aParent = aContext->shape();
132 // store full shape hierarchy for the corresponding version only
133 theObjects.addObject(anObject);
134 theObjects.addParent(anObject, aParent);
135 if (isStoreFullHierarchy)
136 ModelAPI_Tools::fillShapeHierarchy(aParent, aContext, theObjects);
137 } else { // get it from a feature
138 FeaturePtr aFeature = anObjectAttr->contextFeature();
139 if (aFeature.get()) {
140 aParent = aFeature->firstResult()->shape();
145 collectSubs(aParent, anEdges, GeomAPI_Shape::EDGE);
146 for (ListOfShape::iterator anIt = anEdges.begin(); anIt != anEdges.end(); ++anIt) {
147 theObjects.addObject(*anIt);
148 theObjects.addParent(*anIt, aParent);