1 // Copyright (C) 2017-2019 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"
21 #include "FeaturesPlugin_Tools.h"
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_Tools.h>
26 #include <GeomAlgoAPI_MakeShapeList.h>
28 #include <GeomAPI_ShapeExplorer.h>
31 static const std::string CHAMFERFILLET_VERSION_1("v9.5");
34 // Obtain all sub-shapes from the shape and append them to the list
35 static void collectSubs(const GeomShapePtr& theShape,
37 const GeomAPI_Shape::ShapeType theShapeType)
39 GeomAPI_ShapeExplorer anExp(theShape, theShapeType);
40 for (; anExp.more(); anExp.next()) {
41 GeomShapePtr aShape = anExp.current();
42 // Store all shapes with FORWARD orientation to avoid duplication of shared edges/vertices
43 aShape->setOrientation(GeomAPI_Shape::FORWARD);
44 theSubs.push_back(aShape);
49 void FeaturesPlugin_VersionedChFi::initVersion(const AttributePtr& theObjectsAttr)
51 if (!theObjectsAttr->isInitialized()) {
52 // new feature, not read from file
53 data()->setVersion(CHAMFERFILLET_VERSION_1);
57 void FeaturesPlugin_VersionedChFi::execute()
59 GeomAPI_ShapeHierarchy anObjectHierarchy;
60 if (!processAttribute(objectsAttribute(), anObjectHierarchy))
63 // Perform the operation
64 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList);
69 ListOfShape anOriginalSolids;
70 for (GeomAPI_ShapeHierarchy::iterator anIt = anObjectHierarchy.begin();
71 anIt != anObjectHierarchy.end(); ++anIt) {
72 GeomShapePtr aSolid = anObjectHierarchy.parent(*anIt);
73 const ListOfShape& aSubs = anObjectHierarchy.objects(aSolid);
75 std::shared_ptr<GeomAlgoAPI_MakeShape> anAlgo = performOperation(aSolid, aSubs);
77 return; // something gone wrong
79 anObjectHierarchy.markModified(aSolid, anAlgo->shape());
80 aMakeShapeList->appendAlgo(anAlgo);
82 anOriginalSolids.push_back(aSolid);
83 anEdges.insert(anEdges.end(), aSubs.begin(), aSubs.end());
86 // Build results of the operaion.
87 const std::string& aPrefix = modifiedShapePrefix();
88 ListOfShape aTopLevel;
89 anObjectHierarchy.topLevelObjects(aTopLevel);
90 for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt) {
91 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
92 FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalSolids, ListOfShape(),
93 aMakeShapeList, *anIt, aPrefix);
94 setResult(aResultBody, aResultIndex++);
96 for (ListOfShape::iterator anIt = anEdges.begin(); anIt != anEdges.end(); ++anIt) {
97 GeomShapePtr aBase = *anIt;
98 // Store new faces generated from edges and vertices
99 aResultBody->loadGeneratedShapes(aMakeShapeList, aBase, GeomAPI_Shape::EDGE, aPrefix, true);
102 FeaturesPlugin_Tools::loadDeletedShapes(aResultBody, GeomShapePtr(), anOriginalSolids,
103 aMakeShapeList, *anIt);
106 removeResults(aResultIndex);
110 bool FeaturesPlugin_VersionedChFi::processAttribute(const AttributePtr& theAttribute,
111 GeomAPI_ShapeHierarchy& theObjects)
113 bool isStoreFullHierarchy = data()->version() == CHAMFERFILLET_VERSION_1;
115 AttributeSelectionListPtr anObjectsSelList =
116 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
117 for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); ++anObjectsIndex) {
118 AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex);
119 GeomShapePtr anObject = anObjectAttr->value();
123 ResultPtr aContext = anObjectAttr->context();
124 GeomShapePtr aParent;
125 if (aContext.get()) {
126 ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext);
127 if (aCtxOwner && aCtxOwner->shape()->shapeType() == GeomAPI_Shape::COMPSOLID)
128 aContext = aCtxOwner;
129 aParent = aContext->shape();
133 // store full shape hierarchy for the corresponding version only
134 theObjects.addObject(anObject);
135 theObjects.addParent(anObject, aParent);
136 if (isStoreFullHierarchy)
137 ModelAPI_Tools::fillShapeHierarchy(aParent, aContext, theObjects);
138 } else { // get it from a feature
139 FeaturePtr aFeature = anObjectAttr->contextFeature();
140 if (aFeature.get()) {
141 aParent = aFeature->firstResult()->shape();
146 collectSubs(aParent, anEdges, GeomAPI_Shape::EDGE);
147 for (ListOfShape::iterator anIt = anEdges.begin(); anIt != anEdges.end(); ++anIt) {
148 theObjects.addObject(*anIt);
149 theObjects.addParent(*anIt, aParent);