X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_PreviewSketchPlane.cpp;h=43d7005ee73ae2f4a4bdcb72b9f5501e68712d3a;hb=8031e4f1c6fb3b346fb3fd24cbdd77b6f9c1efad;hp=1ee9856ff6ca1f18c8daf66c01fabffa008cae86;hpb=b4fa4c082ef0d0e75ee8bf7f3f440b3f9c86e63c;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_PreviewSketchPlane.cpp b/src/PartSet/PartSet_PreviewSketchPlane.cpp index 1ee9856ff..43d7005ee 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.cpp +++ b/src/PartSet/PartSet_PreviewSketchPlane.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 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 @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "PartSet_PreviewSketchPlane.h" @@ -28,7 +27,8 @@ #include #include -#include +#include +#include #include #include @@ -42,169 +42,111 @@ #include -double maximumSize(double theXmin, double theYmin, double theZmin, - double theXmax, double theYmax, double theZmax) -{ - double aSize = fabs(theXmax - theXmin); - double aSizeToCompare = fabs(theYmax - theYmin); - if (aSizeToCompare > aSize) - aSize = aSizeToCompare; - aSizeToCompare = fabs(theZmax - theZmin); - if (aSizeToCompare > aSize) - aSize = aSizeToCompare; - - return aSize; -} - PartSet_PreviewSketchPlane::PartSet_PreviewSketchPlane() - : mySketchDisplayed(false), myOtherSketchSize(0) -{ -} - -void PartSet_PreviewSketchPlane::setOtherSketchParameters(const GeomShapePtr& theOtherSketchFace) + : myPreviewIsDisplayed(false), mySizeOfView(0), myIsUseSizeOfView(false) { - myOtherSketchOrigin = std::shared_ptr(); - myOtherSketchSize = 0; - if (!theOtherSketchFace) - return; - - getShapeParameters(theOtherSketchFace, myOtherSketchOrigin, myOtherSketchSize); } void PartSet_PreviewSketchPlane::eraseSketchPlane(ModuleBase_IWorkshop* theWorkshop, const bool isClearPlane) { - if (mySketchDisplayed) { + if (myPreviewIsDisplayed) { XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); aDisp->eraseAIS(myPlane, false); if (isClearPlane) { - myPlane = NULL; - myOrigin = NULL; - myNormal = NULL; + myPlane = std::shared_ptr(); + myShape = std::shared_ptr(); } - mySketchDisplayed = false; + myPreviewIsDisplayed = false; } } void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch, ModuleBase_IWorkshop* theWorkshop) { - if (mySketchDisplayed) + // plane is visualized only if sketch plane is filled + if (!PartSet_Tools::sketchPlane(theSketch).get()) return; - // plane is visualized only if sketch plane is filled - std::shared_ptr aPlane = PartSet_Tools::sketchPlane(theSketch); - if (!aPlane.get()) + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (!aSelAttr) + return; + + if (myShape.get() && myShape->isSame(aSelAttr->value())) return; - if (!myPlane) { // If planes are not created + XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); + if (myPreviewIsDisplayed) { + aDisp->eraseAIS(myPlane, false); + } + + // Create Preview + // selected linear face parameters + myShape = aSelAttr->value(); + // this case is needed by constructing sketch on a plane, where result shape is equal + // to context result, therefore value() returns NULL and we should use shape of context. + if (!myShape.get() && aSelAttr->context().get()) + myShape = aSelAttr->context()->shape(); + + if (!myShape.get()) { + // Create Preview for default planes std::shared_ptr anOrigin = std::dynamic_pointer_cast( theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); std::shared_ptr aNormal = std::dynamic_pointer_cast( theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - // Create Preview - // default planes parameters - std::shared_ptr anOriginPnt = anOrigin->pnt(); - double aSize = 10;//Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size"); - // another sketch parameters - if (myOtherSketchOrigin) { - anOriginPnt = myOtherSketchOrigin; - aSize = myOtherSketchSize; - setOtherSketchParameters(GeomShapePtr()); - } - else { - // selected linear face parameters - AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) { - std::shared_ptr aSketchExternalFace = aSelAttr->value(); - if (aSketchExternalFace) - getShapeParameters(aSketchExternalFace, anOriginPnt, aSize); - } - } - double aSketchSize = getSketchBoundingBoxSize(theSketch, anOriginPnt); - if (aSketchSize > 0) - aSize = aSketchSize; + double aFaceSize = myIsUseSizeOfView ? mySizeOfView + : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size"); + if (aFaceSize <= Precision::Confusion()) + aFaceSize = 200; // Set default value - myOrigin = anOriginPnt; - myNormal = aNormal->dir(); - myPlane = createPreviewPlane(aSize); + myShape = GeomAlgoAPI_FaceBuilder::squareFace( + myViewCentralPoint.get() ? myViewCentralPoint : anOrigin->pnt(), aNormal->dir(), aFaceSize); } + myPlane = createPreviewPlane(); - XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); - aDisp->displayAIS(myPlane, true, 1/*shaded*/, false); - mySketchDisplayed = true; -} - -void PartSet_PreviewSketchPlane::updatePlaneSize(const CompositeFeaturePtr& theSketch, - ModuleBase_IWorkshop* theWorkshop) -{ - std::shared_ptr anOriginPnt; - double aSize = getSketchBoundingBoxSize(theSketch, anOriginPnt); - if (aSize <= 0) - return; - myOrigin = anOriginPnt; - createPreviewPlane(aSize); + aDisp->displayAIS(myPlane, false/*load object in selection*/, 1/*shaded*/, false); + myPreviewIsDisplayed = true; } -AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane(double theSize) +double maximumSize(double theXmin, double theYmin, double theZmin, + double theXmax, double theYmax, double theZmax) { - std::vector aYZRGB(3, 0); -#ifdef SET_PLANES_COLOR_IN_PREFERENCES - aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color"); -#else - aYZRGB[0] = 225; -#endif - int aR[] = {aYZRGB[0], aYZRGB[1], aYZRGB[2]}; - - std::shared_ptr aFace = - GeomAlgoAPI_FaceBuilder::squareFace(myOrigin, myNormal, theSize); - - if (myPlane.get()) { - myPlane->createShape(aFace); - return myPlane; - } - else { - AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject()); - aAIS->createShape(aFace); - std::vector aColor = Config_PropManager::color("Visualization", "sketch_preview_plane"); - if (aColor.size() == 3) - aAIS->setColor(aColor[0], aColor[1], aColor[2]); - aAIS->setTransparensy(0.8); + double aSize = fabs(theXmax - theXmin); + double aSizeToCompare = fabs(theYmax - theYmin); + if (aSizeToCompare > aSize) + aSize = aSizeToCompare; + aSizeToCompare = fabs(theZmax - theZmin); + if (aSizeToCompare > aSize) + aSize = aSizeToCompare; - int aDispMode = 1; // shading - Handle(AIS_InteractiveObject) anAISIO = aAIS->impl(); - if (!anAISIO.IsNull()) { - anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True ); - anAISIO->SetDisplayMode(aDispMode); - } - return aAIS; - } + return aSize; } -void PartSet_PreviewSketchPlane::getShapeParameters(const GeomShapePtr& theShape, - std::shared_ptr& theOrigin, - double& theSize) +bool PartSet_PreviewSketchPlane::getDefaultSizeOfView( + const CompositeFeaturePtr& theSketch, double& theSizeOfView, + std::shared_ptr& theCentralPnt) { - theOrigin = GeomAlgoAPI_ShapeTools::centreOfMass(theShape); - - // Create rectangular face close to the selected - double aXmin, anYmin, aZmin, aXmax, anYmax, aZmax; - theShape->computeSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); - - theSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); -} + if (!PartSet_Tools::sketchPlane(theSketch).get()) + return false; + + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) { + myShape = aSelAttr->value(); + // this case is needed by constructing sketch on a plane, where result shape is equal + // to context result, therefore value() returns NULL and we should use shape of context. + if (!myShape.get() && aSelAttr->context().get()) + myShape = aSelAttr->context()->shape(); + } -double PartSet_PreviewSketchPlane::getSketchBoundingBoxSize( - const std::shared_ptr& theSketch, - std::shared_ptr& theCentralPnt) -{ - if (!theSketch.get() || theSketch->numberOfSubs() == 0) - return 0; + if (myShape.get()) + return false; Bnd_Box aBox; - for (int aSubFeatureId = 0; aSubFeatureId < theSketch->numberOfSubs(); aSubFeatureId++) { + int aNumberOfSubs = theSketch->numberOfSubs(); + for (int aSubFeatureId = 0; aSubFeatureId < aNumberOfSubs; aSubFeatureId++) { FeaturePtr aFeature = theSketch->subFeature(aSubFeatureId); if (!aFeature.get()) continue; @@ -228,12 +170,46 @@ double PartSet_PreviewSketchPlane::getSketchBoundingBoxSize( double aXmin, aXmax, anYmin, anYmax, aZmin, aZmax; aBox.Get(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); - double aSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); - if (aSize > 0) { + theSizeOfView = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); + if (theSizeOfView > 0) { gp_Pnt aCentre(aXmax-fabs(aXmax-aXmin)/2., anYmax-fabs(anYmax-anYmin)/2., aZmax - fabs(aZmax-aZmin)/2.); theCentralPnt = std::shared_ptr(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z())); } - return aSize; -} \ No newline at end of file + return true; +} + +void PartSet_PreviewSketchPlane::setSizeOfView(double theSizeOfView, bool isUseSizeOfView, + const std::shared_ptr& theCentralPoint) +{ + mySizeOfView = theSizeOfView; + myIsUseSizeOfView = isUseSizeOfView; + + myViewCentralPoint = theCentralPoint; +} + +AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane() +{ + if (myPlane.get()) { + myPlane->createShape(myShape); + return myPlane; + } + else { + AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject()); + aAIS->createShape(myShape); + std::vector aColor = Config_PropManager::color("Visualization", "sketch_preview_plane"); + if (aColor.size() == 3) + aAIS->setColor(aColor[0], aColor[1], aColor[2]); + aAIS->setTransparensy(0.8); + + int aDispMode = 1; // shading + Handle(AIS_InteractiveObject) anAISIO = aAIS->impl(); + if (!anAISIO.IsNull()) { + //anAISIO->SetInfiniteState(Standard_True); + anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True ); + anAISIO->SetDisplayMode(aDispMode); + } + return aAIS; + } +}