From 674e60d84265e00a9da2d59c9ce293c7339b6087 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 12 Jan 2017 16:13:09 +0300 Subject: [PATCH] Issue #1984: Provide selection of another sketch in object browser for a plane of the current sketch --- src/PartSet/PartSet_WidgetSketchLabel.cpp | 69 +++++++++++++++-------- src/PartSet/PartSet_WidgetSketchLabel.h | 17 +++--- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e87806f74..a45de9121 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -259,7 +259,6 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs // 2. if the planes were displayed, change the view projection const GeomShapePtr& aShape = thePrs->shape(); std::shared_ptr aGShape; - std::shared_ptr aBaseShape; DataPtr aData = feature()->data(); AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast @@ -268,20 +267,33 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs // selection happens in OCC viewer if (aShape.get() && !aShape->isNull()) { aGShape = aShape; - - if (aSelAttr && aSelAttr->context()) { - aBaseShape = aSelAttr->context()->shape(); - } } else { // selection happens in OCC viewer(on body) of in the OB browser if (aSelAttr) { aGShape = aSelAttr->value(); } } + // If the selected object is a sketch then use its plane + std::shared_ptr aPlane; + ObjectPtr aObj = thePrs->object(); + if (aObj.get()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature.get() && (aFeature != feature())) { + if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { + CompositeFeaturePtr aSketch = + std::dynamic_pointer_cast(aFeature); + aPlane = PartSet_Tools::sketchPlane(aSketch); + } + } + } if (aGShape.get() != NULL) { // get plane parameters - std::shared_ptr aFace(new GeomAPI_Face(aGShape)); - std::shared_ptr aPlane = aFace->getPlane(); + if (!aPlane.get()) { + std::shared_ptr aFace(new GeomAPI_Face(aGShape)); + aPlane = aFace->getPlane(); + } + if (!aPlane.get()) + return; std::shared_ptr aDir = aPlane->direction(); gp_XYZ aXYZ = aDir->impl().XYZ(); double aTwist = 0.0; @@ -378,7 +390,7 @@ void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAtt bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs) { - return fillSketchPlaneBySelection(feature(), thePrs); + return fillSketchPlaneBySelection(thePrs); } bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs) @@ -411,16 +423,27 @@ bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& the return aCanFillSketch; } -bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& theFeature, - const ModuleBase_ViewerPrsPtr& thePrs) +bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_ViewerPrsPtr& thePrs) { bool isOwnerSet = false; const GeomShapePtr& aShape = thePrs->shape(); std::shared_ptr aDir; - if (thePrs->object() && (theFeature != thePrs->object())) { - DataPtr aData = theFeature->data(); + 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(aFeature); + std::shared_ptr aPlane = PartSet_Tools::sketchPlane(aSketch); + if (aPlane.get()) { + aDir = setSketchPlane(aPlane); + return aDir.get(); + } + } + } + DataPtr aData = feature()->data(); AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); @@ -443,7 +466,7 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& the } else if (aShape.get() && !aShape->isNull()) { const TopoDS_Shape& aTDShape = aShape->impl(); - aDir = setSketchPlane(theFeature, aTDShape); + aDir = setSketchPlane(aTDShape); isOwnerSet = aDir.get(); } return isOwnerSet; @@ -476,9 +499,6 @@ void PartSet_WidgetSketchLabel::activateCustom() activateSelection(true); - //myLabel->setText(myText); - //myLabel->setToolTip(myTooltip); - connect(XGUI_Tools::workshop(myWorkshop)->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); activateFilters(true); @@ -514,8 +534,8 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate) } -std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const FeaturePtr& theFeature, - const TopoDS_Shape& theShape) +std::shared_ptr + PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape) { if (theShape.IsNull()) return std::shared_ptr(); @@ -524,18 +544,21 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Fea std::shared_ptr aGShape(new GeomAPI_Shape); aGShape->setImpl(new TopoDS_Shape(theShape)); - - // get plane parameters std::shared_ptr aFace(new GeomAPI_Face(aGShape)); std::shared_ptr aPlane = aFace->getPlane(); if (!aPlane.get()) return std::shared_ptr(); + return setSketchPlane(aPlane); +} +std::shared_ptr + PartSet_WidgetSketchLabel::setSketchPlane(std::shared_ptr thePlane) +{ // set plane parameters to feature - std::shared_ptr aData = theFeature->data(); + std::shared_ptr aData = feature()->data(); double anA, aB, aC, aD; - aPlane->coefficients(anA, aB, aC, aD); + thePlane->coefficients(anA, aB, aC, aD); // calculate attributes of the sketch std::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); @@ -560,7 +583,7 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Fea std::shared_ptr aDirX = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::DIRX_ID())); aDirX->setValue(aXDir); - std::shared_ptr aDir = aPlane->direction(); + std::shared_ptr aDir = thePlane->direction(); return aDir; } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index b4606e57a..a89a6167d 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -78,12 +78,6 @@ public: /// \param thePrs a presentation static bool canFillSketch(const std::shared_ptr& thePrs); - /// Set sketch plane from selected object - /// \param theFeature a feature of sketch - /// \param thePrs a presentation - static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature, - const std::shared_ptr& thePrs); - signals: /// Signal on plane selection void planeSelected(const std::shared_ptr& thePln); @@ -153,6 +147,11 @@ protected: /// \param thePrs a selected presentation void updateByPlaneSelected(const std::shared_ptr& thePrs); + /// Set sketch plane from selected object + /// \param theFeature a feature of sketch + /// \param thePrs a presentation + bool fillSketchPlaneBySelection(const std::shared_ptr& thePrs); + protected: /// Activate or deactivate selection void activateSelection(bool toActivate); @@ -171,9 +170,11 @@ protected: private: /// Set sketch plane by shape /// \param theShape a planar face - static std::shared_ptr setSketchPlane(const FeaturePtr& theFeature, - const TopoDS_Shape& theShape); + std::shared_ptr setSketchPlane(const TopoDS_Shape& theShape); + /// Set sketch plane + /// \param thePlane a plane + std::shared_ptr setSketchPlane(std::shared_ptr thePlane); private: /// class to show/hide preview planes -- 2.39.2