-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
if (myPreviewIsDisplayed) {
XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
aDisp->eraseAIS(myPlane, false);
- if (isClearPlane) {
- myPlane = std::shared_ptr<GeomAPI_AISObject>();
- myShape = std::shared_ptr<GeomAPI_Shape>();
- }
myPreviewIsDisplayed = false;
}
+ if (isClearPlane) clearPlanePreview();
}
+void PartSet_PreviewSketchPlane::displaySketchPlane(ModuleBase_IWorkshop* theWorkshop)
+{
+ if (myPlane.get() && (!myPreviewIsDisplayed)) {
+ XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
+ aDisp->displayAIS(myPlane, false/*load object in selection*/, 1/*shaded*/, false);
+ myPreviewIsDisplayed = true;
+ }
+}
+
+
+void PartSet_PreviewSketchPlane::clearPlanePreview()
+{
+ myPlane = std::shared_ptr<GeomAPI_AISObject>();
+ myShape = std::shared_ptr<GeomAPI_Shape>();
+}
+
+
void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch,
ModuleBase_IWorkshop* theWorkshop)
{
- // the preview plane has been already created and displayed
- if (myPreviewIsDisplayed)
- return;
-
// plane is visualized only if sketch plane is filled
if (!PartSet_Tools::sketchPlane(theSketch).get())
return;
- if (!myPlane) { // If planes are not created
- // Create Preview
- // selected linear face parameters
- AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (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()) {
- // Create Preview for default planes
- std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
- double aFaceSize = myIsUseSizeOfView ? mySizeOfView
- : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size");
- if (aFaceSize <= Precision::Confusion())
- aFaceSize = 200; // Set default value
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (!aSelAttr)
+ return;
+ if (myShape.get() && myShape->isSame(aSelAttr->value()) && myPlane.get())
+ return;
+
+ 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<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+
+ 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);
+ }
+ else if (myIsUseSizeOfView && (mySizeOfView > 0)) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(myShape));
+ std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
+ if (aPlane.get()) {
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+ std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+ std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+ aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+ std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
myShape = GeomAlgoAPI_FaceBuilder::squareFace(
- myViewCentralPoint.get() ? myViewCentralPoint : anOrigin->pnt(), aNormal->dir(), aFaceSize);
+ myViewCentralPoint.get() ? myViewCentralPoint : anOrigPnt, aNormDir, mySizeOfView);
}
- myPlane = createPreviewPlane();
}
+ myPlane = createPreviewPlane();
- XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
aDisp->displayAIS(myPlane, false/*load object in selection*/, 1/*shaded*/, false);
myPreviewIsDisplayed = true;
}