X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Plane.cpp;h=13ae2b36d65cb7fe6ca22bcdeb2f398b22172352;hb=1b9dd3633d644c358424227423b330e9551be38f;hp=501d9664e7762c01e75548bf4a8c275445a181b7;hpb=247fc0bd6c6e04ce1f7a6e67f8d3c80ce17acab0;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 501d9664e..13ae2b36d 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -12,29 +12,86 @@ #include #include #include +#include +#include +#include #include #include - -#define PLANE_SIZE 300 - ConstructionPlugin_Plane::ConstructionPlugin_Plane() { } void ConstructionPlugin_Plane::initAttributes() { - data()->addAttribute(ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection::type()); - data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::typeId()); + // Face & Distance + data()->addAttribute(ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::typeId()); + // General equation + data()->addAttribute(ConstructionPlugin_Plane::A(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Plane::B(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Plane::C(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::A()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::B()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::C()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::D()); } void ConstructionPlugin_Plane::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Plane::METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + std::shared_ptr aPlaneFace; + if (aMethodType == "PlaneByFaceAndDistance") { + aPlaneFace = createPlaneByFaceAndDistance(); + } else if (aMethodType == "PlaneByGeneralEquation") { + aPlaneFace = createPlaneByGeneralEquation(); + } + if (!aPlaneFace.get()) + return; + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setShape(aPlaneFace); + setResult(aConstr); +} + +bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) +{ + std::vector aColor; + // get color from the attribute of the result + if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { + AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get() && aColorAttr->size()) { + aColor.push_back(aColorAttr->value(0)); + aColor.push_back(aColorAttr->value(1)); + aColor.push_back(aColorAttr->value(2)); + } + } + if (aColor.empty()) + aColor = Config_PropManager::color("Visualization", "construction_plane_color", + ConstructionPlugin_Plane::DEFAULT_COLOR()); + + bool isCustomized = false; + if (aColor.size() == 3) + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); + + isCustomized = thePrs->setTransparensy(0.6) || isCustomized; + + return isCustomized; +} + +std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDistance() { AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::FACE()); AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE()); - if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) && - aFaceAttr->isInitialized() && aDistAttr->isInitialized()) { + std::shared_ptr aPlane; + if ((aFaceAttr.get() != NULL) && + (aDistAttr.get() != NULL) && + aFaceAttr->isInitialized() && aDistAttr->isInitialized()) { double aDist = aDistAttr->value(); GeomShapePtr aShape = aFaceAttr->value(); @@ -44,17 +101,17 @@ void ConstructionPlugin_Plane::execute() std::shared_ptr aDir = aPln->direction(); aOrig->translate(aDir, aDist); - std::shared_ptr aNewPln = - std::shared_ptr(new GeomAPI_Pln(aOrig, aDir)); + std::shared_ptr aNewPln = std::shared_ptr( + new GeomAPI_Pln(aOrig, aDir)); // Create rectangular face close to the selected double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax; aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax); - std::shared_ptr aPnt1 = - std::shared_ptr(new GeomAPI_Pnt(aXmin, aYmin, Zmin)); - std::shared_ptr aPnt2 = - std::shared_ptr(new GeomAPI_Pnt(aXmax, aYmax, Zmax)); + std::shared_ptr aPnt1 = std::shared_ptr( + new GeomAPI_Pnt(aXmin, aYmin, Zmin)); + std::shared_ptr aPnt2 = std::shared_ptr( + new GeomAPI_Pnt(aXmax, aYmax, Zmax)); std::shared_ptr aPnt2d1 = aPnt1->to2D(aNewPln); std::shared_ptr aPnt2d2 = aPnt2->to2D(aNewPln); @@ -64,38 +121,36 @@ void ConstructionPlugin_Plane::execute() double aWgap = aWidth * 0.1; double aHgap = aHeight * 0.1; - std::shared_ptr aPlane = - GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, aPnt2d1->x() - aWgap, aPnt2d1->y() - aHgap, - aWidth + 2 * aWgap, aHeight + 2 * aHgap); - ResultConstructionPtr aConstr = document()->createConstruction(data()); - aConstr->setShape(aPlane); - setResult(aConstr); + aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, + aPnt2d1->x() - aWgap, + aPnt2d1->y() - aHgap, + aWidth + 2 * aWgap, + aHeight + 2 * aHgap); } } + return aPlane; } -bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) +std::shared_ptr ConstructionPlugin_Plane::createPlaneByGeneralEquation() { - std::vector aColor; - // get color from the attribute of the result - if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { - AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); - if (aColorAttr.get() && aColorAttr->size()) { - aColor.push_back(aColorAttr->value(0)); - aColor.push_back(aColorAttr->value(1)); - aColor.push_back(aColorAttr->value(2)); - } + AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A()); + AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B()); + AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C()); + AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D()); + std::shared_ptr aPlaneFace; + if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) && + (anAttrC.get() != NULL) && (anAttrD.get() != NULL) && + anAttrA->isInitialized() && anAttrB->isInitialized() && + anAttrC->isInitialized() && anAttrD->isInitialized() ) { + double aA = anAttrA->value(), aB = anAttrB->value(), + aC = anAttrC->value(), aD = anAttrD->value(); + std::shared_ptr aPlane = + std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); + std::string kDefaultPlaneSize = "200"; + double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize); + aSize *= 4.; + aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize); } - if (aColor.empty()) - aColor = Config_PropManager::color("Visualization", "construction_plane_color", - ConstructionPlugin_Plane::DEFAULT_COLOR()); - - bool isCustomized = false; - if (aColor.size() == 3) - isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); - - isCustomized = thePrs->setTransparensy(0.6) || isCustomized; - - return isCustomized; + return aPlaneFace; } +