#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Tools.h>
-#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAPI_AISObject.h>
#include <XGUI_Tools.h>
#include <XGUI_Displayer.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_SketchEntity.h>
-#include <BRepBndLib.hxx>
-
-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)
{
- myOtherSketchOrigin = std::shared_ptr<GeomAPI_Pnt>();
- 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;
+ myShape = NULL;
}
- mySketchDisplayed = false;
+ myPreviewIsDisplayed = false;
}
}
void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch,
ModuleBase_IWorkshop* theWorkshop)
{
- if (mySketchDisplayed)
+ // the preview plane has been already created and displayed
+ if (myPreviewIsDisplayed)
return;
// plane is visualized only if sketch plane is filled
- std::shared_ptr<GeomAPI_Pln> aPlane = PartSet_Tools::sketchPlane(theSketch);
- if (!aPlane.get())
+ if (!PartSet_Tools::sketchPlane(theSketch).get())
return;
if (!myPlane) { // If planes are not created
- 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()));
-
// Create Preview
- // default planes parameters
- std::shared_ptr<GeomAPI_Pnt> anOriginPnt = anOrigin->pnt();
- double aSize = 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<ModelAPI_AttributeSelection>
- (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
- if (aSelAttr) {
- std::shared_ptr<GeomAPI_Shape> aSketchExternalFace = aSelAttr->value();
- if (aSketchExternalFace)
- getShapeParameters(aSketchExternalFace, anOriginPnt, aSize);
- }
+ // selected linear face parameters
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr)
+ myShape = aSelAttr->value();
+
+ 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()));
+ myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(),
+ Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size"));
}
- double aSketchSize = getSketchBoundingBoxSize(theSketch, anOriginPnt);
- if (aSketchSize > 0)
- aSize = aSketchSize;
-
- myOrigin = anOriginPnt;
- myNormal = aNormal->dir();
- myPlane = createPreviewPlane(aSize);
+ 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<GeomAPI_Pnt> anOriginPnt;
- double aSize = getSketchBoundingBoxSize(theSketch, anOriginPnt);
- if (aSize <= 0)
- return;
- myOrigin = anOriginPnt;
- createPreviewPlane(aSize);
+ myPreviewIsDisplayed = true;
}
-AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane(double theSize)
+AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane()
{
- std::vector<int> 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<GeomAPI_Shape> aFace =
- GeomAlgoAPI_FaceBuilder::squareFace(myOrigin, myNormal, theSize);
-
if (myPlane.get()) {
- myPlane->createShape(aFace);
+ myPlane->createShape(myShape);
return myPlane;
}
else {
AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
- aAIS->createShape(aFace);
+ aAIS->createShape(myShape);
std::vector<int> aColor = Config_PropManager::color("Visualization", "sketch_preview_plane");
if (aColor.size() == 3)
aAIS->setColor(aColor[0], aColor[1], aColor[2]);
return aAIS;
}
}
-
-void PartSet_PreviewSketchPlane::getShapeParameters(const GeomShapePtr& theShape,
- std::shared_ptr<GeomAPI_Pnt>& theOrigin,
- double& theSize)
-{
- 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);
-}
-
-double PartSet_PreviewSketchPlane::getSketchBoundingBoxSize(
- const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
- std::shared_ptr<GeomAPI_Pnt>& theCentralPnt)
-{
- if (!theSketch.get() || theSketch->numberOfSubs() == 0)
- return 0;
-
- Bnd_Box aBox;
- for (int aSubFeatureId = 0; aSubFeatureId < theSketch->numberOfSubs(); aSubFeatureId++) {
- FeaturePtr aFeature = theSketch->subFeature(aSubFeatureId);
- if (!aFeature.get())
- continue;
-
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aResultIt;
- for (aResultIt = aResults.begin(); aResultIt != aResults.end(); ++aResultIt) {
- ResultPtr aResult = *aResultIt;
- std::shared_ptr<GeomAPI_Shape> aShapePtr = aResult->shape();
- if (aShapePtr.get()) {
- TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
- 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);
-
- double aSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
- if (aSize > 0) {
- gp_Pnt aCentre(aXmax-fabs(aXmax-aXmin)/2., anYmax-fabs(anYmax-anYmin)/2.,
- aZmax - fabs(aZmax-aZmin)/2.);
- theCentralPnt = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(),
- aCentre.Z()));
- }
- return aSize;
-}
\ No newline at end of file
#ifndef PartSet_PreviewSketchPlane_H
#define PartSet_PreviewSketchPlane_H
-#include <GeomAPI_AISObject.h>
-
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Dir.h>
-#include <GeomAPI_AISObject.h>
+class GeomAPI_AISObject;
+class GeomAPI_Shape;
class ModuleBase_IWorkshop;
class ModelAPI_CompositeFeature;
+#include <memory>
+
/**
* \class PartSet_PreviewSketchPlane
* \ingroup Modules
~PartSet_PreviewSketchPlane() {};
- /// Returns if the sketch plane was displayed
- /// \return boolean value
- bool isSketchDisplayed() const { return mySketchDisplayed; }
-
- /// Sets parameters of another sketch to be used in createSketchPlane().
- /// \param theOtherSketchFace a shape of other selected sketch. It is a planar face.
- void setOtherSketchParameters(const std::shared_ptr<GeomAPI_Shape>& theOtherSketchFace);
-
/// Erase preview planes
/// \param theWorkshop the application workshop
/// \param isClearPlane flag whether the plane, origin and normal should be nullified
void createSketchPlane(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
ModuleBase_IWorkshop* theWorkshop);
- /// Resize plane size by sketch content
- /// \param theSketch source sketch to build sketch sub features bounding box
- /// \param theWorkshop the application workshop
- void updatePlaneSize(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
- ModuleBase_IWorkshop* theWorkshop);
-
private:
/// Create a square face by parameters
- /// \param theSize a size of created square
- AISObjectPtr createPreviewPlane(double theSize);
-
- /// Finds origin and maximum size of the shape
- /// \param theShape source shape
- /// \param theOrigin a shape center of mass
- /// \param theSize maximum of delta X, Y or Z
- void getShapeParameters(const std::shared_ptr<GeomAPI_Shape>& theShape,
- std::shared_ptr<GeomAPI_Pnt>& theOrigin,
- double& theSize);
-
- /// Calculate maximum bounding box size of sketch sub features
- /// \param theSketch source sketch to build sketch sub features bounding box
- /// \param theCentralPoint central point of the sketch sub features
- /// \return double value
- double getSketchBoundingBoxSize(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
- std::shared_ptr<GeomAPI_Pnt>& theCentralPnt);
+ std::shared_ptr<GeomAPI_AISObject> createPreviewPlane();
private:
- bool mySketchDisplayed;
- AISObjectPtr myPlane;
- std::shared_ptr<GeomAPI_Pnt> myOrigin; //! an origin of the plane
- std::shared_ptr<GeomAPI_Dir> myNormal; //! a normal vector of the plane
-
- std::shared_ptr<GeomAPI_Pnt> myOtherSketchOrigin;
- double myOtherSketchSize;
+ bool myPreviewIsDisplayed;
+ std::shared_ptr<GeomAPI_AISObject> myPlane; //! visualized presentation
+ std::shared_ptr<GeomAPI_Shape> myShape; //! current shape to be displayed
};
#endif
\ No newline at end of file
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
if (aModule) {
- // if selected object is a shape of another sketch, the origin of selected shape does not stored
- // in argument, so we need to find parameters of selected shape on the sketch
- if (thePrs->object() && (feature() != thePrs->object())) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
- if (aFeature.get() && (aFeature != feature())) {
- if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
- CompositeFeaturePtr aSketch =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
- std::shared_ptr<GeomAPI_Pln> aPlane = PartSet_Tools::sketchPlane(aSketch);
- if (aPlane.get())
- aModule->sketchMgr()->previewSketchPlane()->setOtherSketchParameters(thePrs->shape());
- }
- }
- }
CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
}
// If the selected object is a sketch then use its plane
std::shared_ptr<GeomAPI_Pln> aPlane;
ObjectPtr aObj = thePrs->object();
- if (aObj.get()) {
+ // obsolete as selected sketch is stored in external attribute
+ /*if (aObj.get()) {
FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
if (aFeature.get() && (aFeature != feature())) {
if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
aPlane = PartSet_Tools::sketchPlane(aSketch);
}
}
- }
+ }*/
if (aGShape.get() != NULL) {
// get plane parameters
if (!aPlane.get()) {
if (thePrs->object() && (feature() != thePrs->object())) {
FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
- if (aFeature.get() && (aFeature != feature())) {
- if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
- CompositeFeaturePtr aSketch =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
- std::shared_ptr<GeomAPI_Pln> aPlane = PartSet_Tools::sketchPlane(aSketch);
- if (aPlane.get()) {
- aDir = setSketchPlane(aPlane);
- return aDir.get();
- }
- }
- }
DataPtr aData = feature()->data();
AttributeSelectionPtr aSelAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>