X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetFeaturePointSelector.cpp;h=f44ca020954120fcca6e350e97f48e3fe0d9514a;hb=d7144bf137b2ea4f8c7bfbc6b678e1a762e98653;hp=f2808b3ad2f929397e103f76106c99bd8ee8cc1a;hpb=b707e7178424958f7dc1ed87a0aabd813f671d88;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp index f2808b3ad..f44ca0209 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetFeaturePointSelector.cpp -// Created: 28 Feb 2017 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include @@ -17,6 +30,7 @@ #include #include +#include #include #include #include @@ -28,10 +42,7 @@ #include "PartSet_WidgetFeaturePointSelector.h" #include "PartSet_Tools.h" -//#include -//#include #include -#include #include #include @@ -52,6 +63,13 @@ PartSet_WidgetFeaturePointSelector::PartSet_WidgetFeaturePointSelector(QWidget* const Config_WidgetAPI* theData) : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData) { + std::string anAttributes = theData->getProperty("selection_attributes"); + QStringList anAttributesList = QString(anAttributes.c_str()).split(' ', QString::SkipEmptyParts); + + mySelectedObjectAttribute = anAttributesList[0].toStdString(); + mySelectedPointAttribute = anAttributesList[1].toStdString(); + myPreviewObjectAttribute = anAttributesList[2].toStdString(); + myPreviewPointAttribute = anAttributesList[3].toStdString(); } PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector() @@ -67,14 +85,14 @@ bool PartSet_WidgetFeaturePointSelector::isValidSelection( } //******************************************************************** -bool PartSet_WidgetFeaturePointSelector::activateSelectionAndFilters(bool toActivate) +void PartSet_WidgetFeaturePointSelector::updateSelectionModesAndFilters(bool toActivate) { #ifdef HIGHLIGHT_STAYS_PROBLEM Handle(AIS_InteractiveContext) aContext = XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext(); Quantity_Color aColor; - Handle(Graphic3d_HighlightStyle) aHStyle = aContext->HighlightStyle(); - Handle(Graphic3d_HighlightStyle) aSStyle = aContext->SelectionStyle(); + Handle(Prs3d_Drawer) aHStyle = aContext->HighlightStyle(); + Handle(Prs3d_Drawer) aSStyle = aContext->SelectionStyle(); if (toActivate) { std::vector aColors; aColors = Config_PropManager::color("Visualization", "sketch_entity_color"); @@ -94,7 +112,7 @@ bool PartSet_WidgetFeaturePointSelector::activateSelectionAndFilters(bool toActi #endif - return ModuleBase_WidgetShapeSelector::activateSelectionAndFilters(toActivate); + ModuleBase_WidgetShapeSelector::updateSelectionModesAndFilters(toActivate); } //******************************************************************** @@ -132,28 +150,36 @@ void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* t if (theEvent->button() != Qt::LeftButton) return; + std::shared_ptr aRefPreviewAttr = + std::dynamic_pointer_cast( + feature()->data()->attribute(myPreviewObjectAttribute)); + ObjectPtr aPreviewObject = aRefPreviewAttr->value(); + // do not move focus from the current widget if the object is not highlighted/selected + if (!aPreviewObject.get()) + return; + // set parameters of preview into parameters of selection in the feature std::shared_ptr aRefSelectedAttr = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); - std::shared_ptr aRefPreviewAttr = - std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); + feature()->data()->attribute(mySelectedObjectAttribute)); aRefSelectedAttr->setValue(aRefPreviewAttr->value()); std::shared_ptr aPointSelectedAttr = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::SELECTED_POINT())); + feature()->data()->attribute(mySelectedPointAttribute)); std::shared_ptr aPointPreviewAttr = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); + feature()->data()->attribute(myPreviewPointAttribute)); aPointSelectedAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y()); updateObject(feature()); - emit focusOutWidget(this); // we need to deselect base feature for better visibility of selected feature XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(false); + + // focusOutWidget should be the last functionality in the method because after this emit, + // the widget may be deleted and members of this class are deleted (e.g. myWorkshop) + emit focusOutWidget(this); } //******************************************************************** @@ -167,20 +193,16 @@ bool PartSet_WidgetFeaturePointSelector::fillFeature( if (theSelectedPrs.get() && theSelectedPrs->object().get()) anObject = theSelectedPrs->object(); - gp_Pnt aPnt = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); - double aX, anY; - Handle(V3d_View) aView = theWindow->v3dView(); - PartSet_Tools::convertTo2D(aPnt, mySketch, aView, aX, anY); - std::shared_ptr aRef = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); + feature()->data()->attribute(myPreviewObjectAttribute)); aRef->setValue(anObject); std::shared_ptr anAttributePoint = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); - anAttributePoint->setValue(aX, anY); + feature()->data()->attribute(myPreviewPointAttribute)); + std::shared_ptr aPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch); + anAttributePoint->setValue(aPoint); // redisplay AIS presentation in viewer #ifndef HIGHLIGHT_STAYS_PROBLEM // an attempt to clear highlighted item in the viewer: but of OCCT @@ -214,6 +236,7 @@ void PartSet_WidgetFeaturePointSelector::setPreSelection( ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { - if (fillFeature(thePreSelected, theWnd, theEvent)) - mouseReleased(theWnd, theEvent); + // the method is empty because firstly by starging of the feature there is no selection of + // sub-segments in the viewer, secondly preselection of restart operation is processed by + // special reentrant message sent by the feature }