From: nds Date: Mon, 13 Apr 2015 07:49:41 +0000 (+0300) Subject: Face selection for sketch entity - the OB selected result should be checked on face... X-Git-Tag: V_1.1.0~44 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c55b14977783111c8b418b416c7f6c2fa545c5e5;p=modules%2Fshaper.git Face selection for sketch entity - the OB selected result should be checked on face type. --- diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp index 821b45cb0..0fe74f808 100644 --- a/src/GeomValidators/GeomValidators_Face.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -46,16 +46,21 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast (theAttribute); std::shared_ptr aGeomShape = aSelectionAttr->value(); - std::shared_ptr aGeomFace(new GeomAPI_Face(aGeomShape)); - if (aGeomFace.get() != NULL) { - switch(aFaceType) { - case GeomAbs_Plane: - aValid = aGeomFace->isPlanar(); - break; - case GeomAbs_Cylinder: - break; - default: - break; + // it is necessary to check whether the shape is face in order to set in selection a value + // with any type and check the type in this validator + // It is realized to select any object in OB and filter it in this validator (sketch plane) + if (aGeomShape->isFace()) { + std::shared_ptr aGeomFace(new GeomAPI_Face(aGeomShape)); + if (aGeomFace.get() != NULL) { + switch(aFaceType) { + case GeomAbs_Plane: + aValid = aGeomFace->isPlanar(); + break; + case GeomAbs_Cylinder: + break; + default: + break; + } } } } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 494513096..676094940 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -113,32 +113,36 @@ void PartSet_WidgetSketchLabel::onSelectionChanged() if (aPrs.isEmpty()) return; - if (isValidSelection(aPrs)) { - // 2. set the selection to sketch - setSelectionCustom(aPrs); - // 3. hide main planes if they have been displayed - erasePreviewPlanes(); - // 4. if the planes were displayed, change the view projection - TopoDS_Shape aShape = aPrs.shape(); - if (!aShape.IsNull()) { - DataPtr aData = feature()->data(); - AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) { - GeomShapePtr aShapePtr = aSelAttr->value(); - if (aShapePtr.get() == NULL || aShapePtr->isNull()) { - //TopoDS_Shape aShape = aShapePtr->impl(); - std::shared_ptr aGShape(new GeomAPI_Shape); - aGShape->setImpl(new TopoDS_Shape(aShape)); - // get plane parameters - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); - std::shared_ptr aDir = aPlane->direction(); - - myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z()); - } - } + if (!isValidSelection(aPrs)) + return; + + // 2. set the selection to sketch + setSelectionCustom(aPrs); + // 3. hide main planes if they have been displayed + erasePreviewPlanes(); + // 4. if the planes were displayed, change the view projection + TopoDS_Shape aShape = aPrs.shape(); + std::shared_ptr aGShape; + // selection happens in OCC viewer + if (!aShape.IsNull()) { + aGShape = std::shared_ptr(new GeomAPI_Shape); + aGShape->setImpl(new TopoDS_Shape(aShape)); + } + else { // selection happens in OCC viewer(on body) of in the OB browser + DataPtr aData = feature()->data(); + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) { + aGShape = aSelAttr->value(); } } + if (aGShape.get() != NULL) { + // get plane parameters + std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); + std::shared_ptr aDir = aPlane->direction(); + + myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z()); + } // 5. Clear text in the label myLabel->setText(""); myLabel->setToolTip(""); @@ -210,14 +214,16 @@ bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrs& t ResultPtr aRes = std::dynamic_pointer_cast(thePrs.object()); if (aRes) { GeomShapePtr aShapePtr(new GeomAPI_Shape()); - if (aShape.IsNull()) { + if (aShape.IsNull()) { // selection happens in the OCC viewer aShapePtr = ModelAPI_Tools::shape(aRes); } - else { + else { // selection happens in OB browser aShapePtr->setImpl(new TopoDS_Shape(aShape)); } - aSelAttr->setValue(aRes, aShapePtr); - isOwnerSet = true; + if (aShapePtr.get() != NULL) { + aSelAttr->setValue(aRes, aShapePtr); + isOwnerSet = true; + } } } }