-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: FeaturesPlugin_Intersection.cpp
-// Created: 15 Feb 2016
-// Author: Dmitry Bobylev
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
#include "FeaturesPlugin_Intersection.h"
#include <ModelAPI_AttributeSelectionList.h>
#include <GeomAlgoAPI_Intersection.h>
+#include <GeomAPI_ShapeExplorer.h>
#include <sstream>
const ListOfShape& theTools,
GeomAlgoAPI_MakeShape& theMakeShape)
{
- //load result
std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape.shape();
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfShapes = theMakeShape.mapOfSubShapes();
- const int aDeletedTag = 1;
- /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
- const int aSubsolidsTag = 2;
- const int aModifyTag = 100000;
- int aModifyToolsTag = 200000;
- std::ostringstream aStream;
-
- theResultBody->storeModified(theBaseShape, aResultShape, aSubsolidsTag);
-
- std::string aModName = "Modified";
- theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::VERTEX,
- aModifyTag, aModName, *aMapOfShapes.get(), true);
- theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::EDGE,
- aModifyTag, aModName, *aMapOfShapes.get(), true);
- theResultBody->loadDeletedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE, aDeletedTag);
-
- int anIndex = 1;
- for(ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) {
- aStream.str(std::string());
- aStream.clear();
- aStream << aModName << "_" << anIndex++;
- theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter, GeomAPI_Shape::VERTEX,
- aModifyToolsTag, aStream.str(), *aMapOfShapes.get(), true);
- theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter, GeomAPI_Shape::EDGE,
- aModifyToolsTag, aStream.str(), *aMapOfShapes.get(), true);
- theResultBody->loadDeletedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, aDeletedTag);
- aModifyToolsTag += 10000;
+ theResultBody->storeModified(theBaseShape, aResultShape);
+
+ const int aDeletedVertexTag = 1;
+ const int aDeletedEdgeTag = 2;
+ const int aDeletedFaceTag = 3;
+
+ theResultBody->loadDeletedShapes(&theMakeShape,
+ theBaseShape,
+ GeomAPI_Shape::VERTEX,
+ aDeletedVertexTag);
+ theResultBody->loadDeletedShapes(&theMakeShape,
+ theBaseShape,
+ GeomAPI_Shape::EDGE,
+ aDeletedEdgeTag);
+ theResultBody->loadDeletedShapes(&theMakeShape,
+ theBaseShape,
+ GeomAPI_Shape::FACE,
+ aDeletedFaceTag);
+
+ ListOfShape aShapes = theTools;
+ aShapes.push_back(theBaseShape);
+ GeomAPI_DataMapOfShapeShape aShapesMap; // Map to store {result_shape, original_shape}
+ const int aShapeTypesNb = 2;
+ const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] =
+ {GeomAPI_Shape::VERTEX, GeomAPI_Shape::EDGE};
+ for(ListOfShape::const_iterator anIt = aShapes.cbegin(); anIt != aShapes.cend(); ++anIt) {
+ const GeomShapePtr aShape = *anIt;
+ for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
+ for(GeomAPI_ShapeExplorer anOrigShapeExp(aShape, aShapeTypes[anIndex]);
+ anOrigShapeExp.more();
+ anOrigShapeExp.next()) {
+ ListOfShape aHistory;
+ const GeomShapePtr aSubShape = anOrigShapeExp.current();
+ theMakeShape.modified(aSubShape, aHistory);
+ for(ListOfShape::const_iterator aHistoryIt = aHistory.cbegin();
+ aHistoryIt != aHistory.cend();
+ ++aHistoryIt) {
+ aShapesMap.bind(*aHistoryIt, aSubShape);
+ }
+ }
+ }
+ }
+
+ int aModifiedVertexIndex(1),
+ aGeneratedVertexIndex(1),
+ aModifiedEdgeIndex(1),
+ aGeneratedEdgeIndex(1);
+ int aTag = 4;
+ GeomAPI_DataMapOfShapeShape aStoredShapes;
+ for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
+ for(GeomAPI_ShapeExplorer aShapeExp(aResultShape, aShapeTypes[anIndex]);
+ aShapeExp.more();
+ aShapeExp.next()) {
+ const GeomShapePtr aSubShape = aShapeExp.current();
+ if(aStoredShapes.isBound(aSubShape)) {
+ continue;
+ }
+ if(aShapesMap.isBound(aSubShape)) {
+ theResultBody->modified(aShapesMap.find(aSubShape),
+ aSubShape,
+ std::string("Modified_")
+ + (anIndex == 0 ? "Vertex_" : "Edge_")
+ + std::to_string((long long)(anIndex == 0 ? aModifiedVertexIndex++
+ : aModifiedEdgeIndex++)),
+ aTag++);
+ } else {
+ theResultBody->generated(aSubShape,
+ std::string("Generated_")
+ + (anIndex == 0 ? "Vertex_" : "Edge_")
+ + std::to_string((long long)(anIndex == 0 ? aGeneratedVertexIndex++
+ : aGeneratedEdgeIndex++)),
+ aTag++);
+ }
+ aStoredShapes.bind(aSubShape, aSubShape);
+ }
}
}