X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Placement.cpp;h=3ba02779f5b5a7cdb10b849ae6676bb742986070;hb=a731f82dccbfdb67cbf8e8d617222a4d3e32018a;hp=96d52d77bb31f3676e959582f57436ddd916ce3d;hpb=5746238455553297ce5333502e6f27e6e5d9348b;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index 96d52d77b..3ba02779f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + // File: FeaturesPlugin_Placement.cpp // Created: 2 Dec 2014 // Author: Artem ZHIDKOV @@ -7,7 +9,9 @@ #include #include #include +#include +#include #include #include #include @@ -22,48 +26,50 @@ FeaturesPlugin_Placement::FeaturesPlugin_Placement() void FeaturesPlugin_Placement::initAttributes() { - data()->addAttribute(FeaturesPlugin_Placement::BASE_FACE_ID(), ModelAPI_AttributeSelection::type()); - data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID(), ModelAPI_AttributeSelection::type()); + data()->addAttribute(FeaturesPlugin_Placement::BASE_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::typeId()); } void FeaturesPlugin_Placement::execute() { // Verify the base face - std::shared_ptr aFaceRef = std::dynamic_pointer_cast< - ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_FACE_ID())); - if (!aFaceRef) + std::shared_ptr anObjRef = std::dynamic_pointer_cast< + ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_OBJECT_ID())); + if (!anObjRef) return; - std::shared_ptr aBaseFace = - std::dynamic_pointer_cast(aFaceRef->value()); - if (!aBaseFace) + std::shared_ptr aBaseShape = + std::dynamic_pointer_cast(anObjRef->value()); + if (!aBaseShape) return; - std::shared_ptr aBaseFaceContext; - ResultPtr aContextRes = aFaceRef->context(); + std::shared_ptr aBaseObject; + ResultPtr aContextRes = anObjRef->context(); if (aContextRes) { if (aContextRes->groupName() == ModelAPI_ResultBody::group()) - aBaseFaceContext = std::dynamic_pointer_cast(aContextRes)->shape(); + aBaseObject = std::dynamic_pointer_cast(aContextRes)->shape(); else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group()) - aBaseFaceContext = std::dynamic_pointer_cast(aContextRes)->shape(); + aBaseObject = std::dynamic_pointer_cast(aContextRes)->shape(); } - if (!aBaseFaceContext) { + if (!aBaseObject) { static const std::string aContextError = "The selection context is bad"; setError(aContextError); return; } // Verify the attractive face - aFaceRef = std::dynamic_pointer_cast( - data()->attribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID())); + anObjRef = std::dynamic_pointer_cast( + data()->attribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID())); - std::shared_ptr aSlaveObjectFace = - std::dynamic_pointer_cast(aFaceRef->value()); - if (!aSlaveObjectFace) + std::shared_ptr aSlaveShape = + std::dynamic_pointer_cast(anObjRef->value()); + if (!aSlaveShape) return; std::shared_ptr aSlaveObject; - aContextRes = aFaceRef->context(); + aContextRes = anObjRef->context(); if (aContextRes) { if (aContextRes->groupName() == ModelAPI_ResultBody::group()) aSlaveObject = std::dynamic_pointer_cast(aContextRes)->shape(); @@ -76,20 +82,37 @@ void FeaturesPlugin_Placement::execute() return; } - // Verify faces planarity - std::shared_ptr aBaseFace1(new GeomAPI_Face(aBaseFace)); - std::shared_ptr aSlaveFace1(new GeomAPI_Face(aSlaveObjectFace)); - if (!aBaseFace1->isPlanar() || !aSlaveFace1->isPlanar()) { - static const std::string aPlanarityError = "One of selected face is not planar"; - setError(aPlanarityError); - return; + // Verify planarity of faces and linearity of edges + std::shared_ptr aShapes[2] = {aBaseShape, aSlaveShape}; + for (int i = 0; i < 2; i++) { + if (aShapes[i]->isFace()) { + std::shared_ptr aFace(new GeomAPI_Face(aShapes[i])); + if (!aFace->isPlanar()) { + static const std::string aPlanarityError = "One of selected faces is not planar"; + setError(aPlanarityError); + return; + } + } + else if (aShapes[i]->isEdge()) { + std::shared_ptr anEdge(new GeomAPI_Edge(aShapes[i])); + if (!anEdge->isLine()) { + static const std::string aLinearityError = "One of selected endges is not linear"; + setError(aLinearityError); + return; + } + } } - std::shared_ptr aBasePlane = aBaseFace1->getPlane(); - std::shared_ptr aSlavePlane = aSlaveFace1->getPlane(); + // Flags of the Placement + AttributeBooleanPtr aBoolAttr = std::dynamic_pointer_cast( + data()->attribute(FeaturesPlugin_Placement::REVERSE_ID())); + bool isReverse = aBoolAttr->value(); + aBoolAttr = std::dynamic_pointer_cast( + data()->attribute(FeaturesPlugin_Placement::CENTERING_ID())); + bool isCentering = aBoolAttr->value(); std::shared_ptr aResultBody = document()->createBody(data()); - GeomAlgoAPI_Placement aFeature(aSlaveObject, aSlavePlane, aBasePlane); + GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering); if(!aFeature.isDone()) { static const std::string aFeatureError = "Placement algorithm failed"; setError(aFeatureError); @@ -124,8 +147,9 @@ void FeaturesPlugin_Placement::LoadNamingDS( GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); theFeature.mapOfShapes(*aSubShapes); - + // put modifed faces in DF - theResultBody->loadAndOrientModifiedShapes(theFeature.makeShape(), theSlaveObject, _FACE, _MODIFIEDF_TAG, *aSubShapes); + std::string aModName = "Modified"; + theResultBody->loadAndOrientModifiedShapes(theFeature.makeShape(), theSlaveObject, _FACE, _MODIFIEDF_TAG, aModName, *aSubShapes); }