X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Plane.cpp;h=07a223b44e5053d8e6180e69eea43f56ca6ddda1;hb=3e7f97125b2198724911564b24b0a30cbd393e3d;hp=7448f5a7e5aa62f5d8bc70b9b403f8593c0fcbdc;hpb=08c3ac23e89dcdc6504121af63731d764e1b6b42;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 7448f5a7e..07a223b44 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -23,15 +25,20 @@ ConstructionPlugin_Plane::ConstructionPlugin_Plane() void ConstructionPlugin_Plane::initAttributes() { - data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::type()); + data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::typeId()); // Face & Distance - data()->addAttribute(ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection::type()); - data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::type()); + 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::type()); - data()->addAttribute(ConstructionPlugin_Plane::B(), ModelAPI_AttributeDouble::type()); - data()->addAttribute(ConstructionPlugin_Plane::C(), ModelAPI_AttributeDouble::type()); - data()->addAttribute(ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble::type()); + 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() @@ -47,6 +54,7 @@ void ConstructionPlugin_Plane::execute() if (!aPlaneFace.get()) return; ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); aConstr->setShape(aPlaneFace); setResult(aConstr); } @@ -88,6 +96,10 @@ std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDi double aDist = aDistAttr->value(); GeomShapePtr aShape = aFaceAttr->value(); + if (!aShape.get()) { + aShape = aFaceAttr->context()->shape(); + } + if (aShape.get() != NULL) { std::shared_ptr aPln = GeomAlgoAPI_FaceBuilder::plane(aShape); std::shared_ptr aOrig = aPln->location(); @@ -101,24 +113,32 @@ std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDi 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 aPnt2d1 = aPnt1->to2D(aNewPln); - std::shared_ptr aPnt2d2 = aPnt2->to2D(aNewPln); - - double aWidth = aPnt2d2->x() - aPnt2d1->x(); - double aHeight = aPnt2d2->y() - aPnt2d1->y(); - double aWgap = aWidth * 0.1; - double aHgap = aHeight * 0.1; - + // use all 8 points of the bounding box to find the 2D bounds + bool isFirst = true; + double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d; + for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) { + for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) { + for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) { + std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt( + aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax)); + std::shared_ptr aPnt2d = aPnt->to2D(aNewPln); + if (isFirst || aPnt2d->x() < aMinX2d) + aMinX2d = aPnt2d->x(); + if (isFirst || aPnt2d->y() < aMinY2d) + aMinY2d = aPnt2d->y(); + if (isFirst || aPnt2d->x() > aMaxX2d) + aMaxX2d = aPnt2d->x(); + if (isFirst || aPnt2d->y() > aMaxY2d) + aMaxY2d = aPnt2d->y(); + if (isFirst) + isFirst = !isFirst; + } + } + } + double aWgap = (aMaxX2d - aMinX2d) * 0.1; + double aHgap = (aMaxY2d - aMinY2d) * 0.1; aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, - aPnt2d1->x() - aWgap, - aPnt2d1->y() - aHgap, - aWidth + 2 * aWgap, - aHeight + 2 * aHgap); + aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap); } } return aPlane;