X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Placement.cpp;h=3ba02779f5b5a7cdb10b849ae6676bb742986070;hb=15d7658e3aa5709c017ecd05905af27e09725830;hp=af86e815255c9bb88d0788cd453e9f1bec155b94;hpb=4c3c61e1535d9fbf5e189796e35d6c238cbac98c;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index af86e8152..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,85 +9,110 @@ #include #include #include +#include +#include #include #include #include +#define _MODIFIEDF_TAG 1 +#define _MODIFIEDE_TAG 2 +#define _MODIFIEDV_TAG 3 +#define _FACE 4 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 anAttractiveFace = - std::dynamic_pointer_cast(aFaceRef->value()); - if (!anAttractiveFace) + std::shared_ptr aSlaveShape = + std::dynamic_pointer_cast(anObjRef->value()); + if (!aSlaveShape) return; - std::shared_ptr anAttractiveFaceContext; - aContextRes = aFaceRef->context(); + std::shared_ptr aSlaveObject; + aContextRes = anObjRef->context(); if (aContextRes) { if (aContextRes->groupName() == ModelAPI_ResultBody::group()) - anAttractiveFaceContext = std::dynamic_pointer_cast(aContextRes)->shape(); + aSlaveObject = std::dynamic_pointer_cast(aContextRes)->shape(); else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group()) - anAttractiveFaceContext = std::dynamic_pointer_cast(aContextRes)->shape(); + aSlaveObject = std::dynamic_pointer_cast(aContextRes)->shape(); } - if (!anAttractiveFaceContext) { + if (!aSlaveObject) { static const std::string aContextError = "The selection context is bad"; setError(aContextError); return; } - // Verify faces planarity - std::shared_ptr aBaseFace1(new GeomAPI_Face(aBaseFace)); - std::shared_ptr anAttractFace1(new GeomAPI_Face(anAttractiveFace)); - if (!aBaseFace1->isPlanar() || !anAttractFace1->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 anAttractivePlane = anAttractFace1->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(anAttractiveFaceContext, anAttractivePlane, aBasePlane); + GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering); if(!aFeature.isDone()) { static const std::string aFeatureError = "Placement algorithm failed"; setError(aFeatureError); @@ -104,7 +131,7 @@ void FeaturesPlugin_Placement::execute() return; } //LoadNamingDS - LoadNamingDS(aFeature, aResultBody, anAttractiveFace, anAttractiveFaceContext); + LoadNamingDS(aFeature, aResultBody, aSlaveObject); setResult(aResultBody); } @@ -113,44 +140,16 @@ void FeaturesPlugin_Placement::execute() void FeaturesPlugin_Placement::LoadNamingDS( GeomAlgoAPI_Placement& theFeature, std::shared_ptr theResultBody, - std::shared_ptr theBasis, - std::shared_ptr theContext) + std::shared_ptr theSlaveObject) { - theResultBody->store(theFeature.shape()); - /// TODO: SZY -/* - //load result - if(theBasis->isEqual(theContext)) - theResultBody->store(theFeature.shape()); - else - theResultBody->storeGenerated(theContext, theFeature.shape()); + theResultBody->storeModified(theSlaveObject, theFeature.shape()); // the initial Slave, the resulting Slave GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); theFeature.mapOfShapes(*aSubShapes); + + // put modifed faces in DF + std::string aModName = "Modified"; + theResultBody->loadAndOrientModifiedShapes(theFeature.makeShape(), theSlaveObject, _FACE, _MODIFIEDF_TAG, aModName, *aSubShapes); - //Insert lateral face : Face from Edge - theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, *aSubShapes); - - //Insert bottom face - std::shared_ptr aBottomFace = theFeature.firstShape(); - if (!aBottomFace->isNull()) { - if (aSubShapes->isBound(aBottomFace)) { - aBottomFace = aSubShapes->find(aBottomFace); - } - theResultBody->generated(aBottomFace, _FIRST_TAG); - } - - - - //Insert top face - std::shared_ptr aTopFace = theFeature.lastShape(); - if (!aTopFace->isNull()) { - if (aSubShapes->isBound(aTopFace)) { - aTopFace = aSubShapes->find(aTopFace); - } - theResultBody->generated(aTopFace, _LAST_TAG); - } - -*/ }