X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_PreviewSketchPlane.cpp;h=808de929f96e6d9d29585f539fd17362759407aa;hb=c5f8e9b29a4ec001befdc58ad894ad9938c840a0;hp=6de85edc74977390ffd94ea3f4230979c65ea3b8;hpb=08f1aef6629e6a63cc4671d271ded4de6e826948;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_PreviewSketchPlane.cpp b/src/PartSet/PartSet_PreviewSketchPlane.cpp index 6de85edc7..808de929f 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.cpp +++ b/src/PartSet/PartSet_PreviewSketchPlane.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -40,8 +41,10 @@ #include #include +#include + PartSet_PreviewSketchPlane::PartSet_PreviewSketchPlane() - : myPreviewIsDisplayed(false) + : myPreviewIsDisplayed(false), mySizeOfView(0), myIsUseSizeOfView(false) { } @@ -75,26 +78,115 @@ void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& th // selected linear face parameters AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) + 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(); + } 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())); - myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(), - Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size")); + + double aFaceSize = myIsUseSizeOfView ? mySizeOfView + : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size"); + if (aFaceSize <= Precision::Confusion()) + aFaceSize = 200; // Set default value + + 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); + aDisp->displayAIS(myPlane, false/*load object in selection*/, 1/*shaded*/, false); myPreviewIsDisplayed = true; } +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; +} + +bool PartSet_PreviewSketchPlane::getDefaultSizeOfView( + const CompositeFeaturePtr& theSketch, double& theSizeOfView, + std::shared_ptr& theCentralPnt) +{ + 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(); + } + + if (myShape.get()) + return false; + + Bnd_Box aBox; + int aNumberOfSubs = theSketch->numberOfSubs(); + for (int aSubFeatureId = 0; aSubFeatureId < aNumberOfSubs; aSubFeatureId++) { + FeaturePtr aFeature = theSketch->subFeature(aSubFeatureId); + if (!aFeature.get()) + continue; + + std::list aResults = aFeature->results(); + std::list::const_iterator aResultIt; + for (aResultIt = aResults.begin(); aResultIt != aResults.end(); ++aResultIt) { + ResultPtr aResult = *aResultIt; + std::shared_ptr aShapePtr = aResult->shape(); + if (aShapePtr.get()) { + TopoDS_Shape aShape = aShapePtr->impl(); + if (aShape.IsNull()) + continue; + BRepBndLib::Add(aShape, aBox); + } + } + } + if (aBox.IsVoid()) + return 0; + + double aXmin, aXmax, anYmin, anYmax, aZmin, aZmax; + aBox.Get(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); + + 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 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()) { @@ -112,6 +204,7 @@ AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane() 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); }