-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022 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
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_ShapeIterator.h>
-//==================================================================================================
-void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
- const ListOfShape& theBaseShapes,
- const ListOfShape& theTools,
- const GeomMakeShapePtr& theMakeShape,
- const GeomShapePtr theResultShape,
- const std::string& theNamePrefix)
-{
- theResultBody->storeModified(theBaseShapes, theResultShape, theMakeShape);
-
- ListOfShape aShapes = theBaseShapes;
- ListOfShape::const_iterator aToolIter = theTools.cbegin();
- for(; aToolIter != theTools.cend(); aToolIter++)
- aShapes.push_back(*aToolIter);
-
- for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); ++anIter)
- {
- theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::VERTEX, theNamePrefix);
- theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::EDGE, theNamePrefix);
- theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE, theNamePrefix);
- }
-}
-
-//==================================================================================================
-void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody,
- const GeomShapePtr& theBaseShape,
- const GeomMakeShapePtr& theMakeShape,
- const std::string theName)
-{
- switch(theBaseShape->shapeType()) {
- case GeomAPI_Shape::COMPOUND: {
- for(GeomAPI_ShapeIterator anIt(theBaseShape); anIt.more(); anIt.next())
- {
- loadModifiedShapes(theResultBody,
- anIt.current(),
- theMakeShape,
- theName);
- }
- break;
- }
- case GeomAPI_Shape::COMPSOLID:
- case GeomAPI_Shape::SOLID:
- case GeomAPI_Shape::SHELL: {
- theResultBody->loadModifiedShapes(theMakeShape,
- theBaseShape,
- GeomAPI_Shape::FACE,
- theName);
- }
- case GeomAPI_Shape::FACE:
- case GeomAPI_Shape::WIRE: {
- theResultBody->loadModifiedShapes(theMakeShape,
- theBaseShape,
- GeomAPI_Shape::EDGE,
- theName);
- }
- case GeomAPI_Shape::EDGE: {
- theResultBody->loadModifiedShapes(theMakeShape,
- theBaseShape,
- GeomAPI_Shape::VERTEX,
- theName);
- }
- }
-}
-
-//==================================================================================================
-void FeaturesPlugin_Tools::loadDeletedShapes(ResultBodyPtr theResultBody,
- const GeomShapePtr theBaseShape,
- const ListOfShape& theTools,
- const GeomMakeShapePtr& theMakeShape,
- const GeomShapePtr theResultShapesCompound)
-{
- ListOfShape aShapes = theTools;
- if (theBaseShape.get())
- aShapes.push_front(theBaseShape);
-
- for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); anIter++)
- {
- theResultBody->loadDeletedShapes(theMakeShape,
- *anIter,
- GeomAPI_Shape::VERTEX,
- theResultShapesCompound);
- theResultBody->loadDeletedShapes(theMakeShape,
- *anIter,
- GeomAPI_Shape::EDGE,
- theResultShapesCompound);
- theResultBody->loadDeletedShapes(theMakeShape,
- *anIter,
- GeomAPI_Shape::FACE,
- theResultShapesCompound);
- }
-}
-
-//==================================================================================================
-void FeaturesPlugin_Tools::loadDeletedShapes(
- std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
- const ListOfShape& theTools,
- const GeomShapePtr theResultShapesCompound)
-{
- for (std::vector<ResultBaseAlgo>::iterator anIt = theResultBaseAlgoList.begin();
- anIt != theResultBaseAlgoList.end();
- ++anIt)
- {
- ResultBaseAlgo& aRCA = *anIt;
- loadDeletedShapes(aRCA.resultBody,
- aRCA.baseShape,
- theTools,
- aRCA.makeShape,
- theResultShapesCompound);
- }
-}
+#include <GeomValidators_ShapeType.h>
//==================================================================================================
bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelectionList,
theError = "Error: Selected sketches does not have results.";
return false;
}
- int aFacesNum = aConstruction->facesNum();
+ GeomValidators_ShapeType::TypeOfShape aSelType =
+ GeomValidators_ShapeType::shapeType(theSelectionList->selectionType());
+ int aFacesNum = 0;
+ if (aSelType != GeomValidators_ShapeType::Vertex &&
+ aSelType != GeomValidators_ShapeType::Edge)
+ aFacesNum = aConstruction->facesNum();
if(aFacesNum == 0) {
// Probably it can be construction.
aBaseShape = aConstruction->shape();
if(aBaseShape.get() && !aBaseShape->isNull()) {
GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType();
- if(aST != GeomAPI_Shape::VERTEX && aST != GeomAPI_Shape::EDGE &&
- aST != GeomAPI_Shape::WIRE &&
- aST != GeomAPI_Shape::FACE && aST != GeomAPI_Shape::SHELL) {
+ if(aST == GeomAPI_Shape::SOLID || aST == GeomAPI_Shape::COMPSOLID) {
theError = "Error: Selected shapes has unsupported type.";
return false;
}
}
return true;
}
+
+//==================================================================================================
+bool FeaturesPlugin_Tools::shapesFromSelectionList(
+ const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
+ const bool theStoreFullHierarchy,
+ GeomAPI_ShapeHierarchy& theHierarchy,
+ std::list<ResultPtr>& theParts, ResultPtr& theTextureSource)
+{
+ int aSize = theSelectionList->size();
+ if (aSize == 1) {
+ auto anObjectAttr = theSelectionList->value(0);
+ if (anObjectAttr.get()) {
+ FeaturePtr aFeature = anObjectAttr->contextFeature();
+ if (aFeature.get() && aFeature->results().size() == 1) {
+ theTextureSource = aFeature->firstResult();
+ }
+ else {
+ if (!aFeature.get()) {
+ auto aResult = anObjectAttr->context();
+ if (aResult.get()) {
+ theTextureSource = aResult;
+ }
+ }
+ }
+ }
+ }
+ for (int anObjectsIndex = 0; anObjectsIndex < aSize; anObjectsIndex++) {
+ AttributeSelectionPtr anObjectAttr = theSelectionList->value(anObjectsIndex);
+ std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+ if (!anObject.get()) { // may be for not-activated parts
+ return false;
+ }
+ ResultPtr aContext = anObjectAttr->context();
+ if (aContext && aContext->groupName() == ModelAPI_ResultPart::group())
+ theParts.push_back(aContext);
+ else {
+ // store full shape hierarchy for the corresponding version only
+ theHierarchy.addObject(anObject);
+ if (theStoreFullHierarchy)
+ ModelAPI_Tools::fillShapeHierarchy(anObject, aContext, theHierarchy);
+ }
+ }
+ return true;
+}