X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetSketchLabel.cpp;h=42d4cd3edecc0d737ba7f675269b026f89cea5c1;hb=05b2338e0d6dd63e13c05476973f231284f5297a;hp=d47fadecdcdc159462422c6fffc9261e4f09d327;hpb=7b9e257dacdb4564754c3bcd0c35817e73a3989c;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index d47fadecd..42d4cd3ed 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -19,6 +19,10 @@ #include #include #include +#include + +#include +#include #include #include @@ -26,6 +30,7 @@ #include #include +#include #include #include @@ -38,15 +43,17 @@ #include #include -#include +//#include #include #include +#include PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId), + const std::string& theParentId, + bool toShowConstraints) + : ModuleBase_WidgetValidated(theParent, theData, theParentId), myPreviewDisplayed(false), myWorkshop(NULL) { @@ -57,14 +64,20 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, myLabel->setToolTip(""); myLabel->setIndent(5); - mySelectionTimer = new QTimer(this); - connect(mySelectionTimer, SIGNAL(timeout()), SLOT(setSketchingMode())); - mySelectionTimer->setSingleShot(true); + //mySelectionTimer = new QTimer(this); + //connect(mySelectionTimer, SIGNAL(timeout()), SLOT(setSketchingMode())); + //mySelectionTimer->setSingleShot(true); QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); aLayout->addWidget(myLabel); + + myShowConstraints = new QCheckBox(tr("Show constraints"), this); + aLayout->addWidget(myShowConstraints); + setLayout(aLayout); + connect(myShowConstraints, SIGNAL(toggled(bool)), this, SIGNAL(showConstraintToggled(bool))); + myShowConstraints->setChecked(toShowConstraints); } PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() @@ -79,53 +92,70 @@ QList PartSet_WidgetSketchLabel::getControls() const return aResult; } -void PartSet_WidgetSketchLabel::onPlaneSelected() +void PartSet_WidgetSketchLabel::onSelectionChanged() { + ModuleBase_ViewerPrs aPrs; + // 1. find selected presentation either in the viewer or in OB XGUI_Selection* aSelection = myWorkshop->selector()->selection(); QList aSelected = aSelection->getSelected(); + // the selection in OCC viewer - the selection of a face in the viewer + // it can be th main plane's face of a face on a visualized body if (!aSelected.empty()) { - ModuleBase_ViewerPrs aPrs = aSelected.first(); + aPrs = aSelected.first(); + } + else { + // the selection in Object Browser: the plane object can be used as sketch plane + QObjectPtrList anObjects = aSelection->selectedObjects(); + if (!anObjects.empty()) { + aPrs.setObject(anObjects.first()); + } + } + 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()) { - std::shared_ptr aDir = setSketchPlane(aShape); - if (aDir) { - erasePreviewPlanes(); - - if (aPrs.object() && (feature() != aPrs.object())) { - DataPtr aData = feature()->data(); - AttributeSelectionPtr aSelAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) { - ResultPtr aRes = std::dynamic_pointer_cast(aPrs.object()); - if (aRes) { - GeomShapePtr aShapePtr(new GeomAPI_Shape()); - aShapePtr->setImpl(new TopoDS_Shape(aShape)); - aSelAttr->setValue(aRes, aShapePtr); - } - } - } else - myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z()); + 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(); - // Clear text in the label - myLabel->setText(""); - myLabel->setToolTip(""); - disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()), - this, SLOT(onPlaneSelected())); - - // Clear selection mode and define sketching mode - XGUI_Displayer* aDisp = myWorkshop->displayer(); - aDisp->removeSelectionFilter(myFaceFilter); - //aDisp->closeLocalContexts(); - emit planeSelected(plane()); - setSketchingMode(); - - // Update sketcher actions - XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr(); - anActMgr->update(); - myWorkshop->viewer()->update(); + myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z()); + } } } + // 5. Clear text in the label + myLabel->setText(""); + myLabel->setToolTip(""); + disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()), + this, SLOT(onSelectionChanged())); + // 6. deactivate face selection filter + activateFilters(myWorkshop->module()->workshop(), false); + + // 7. Clear selection mode and define sketching mode + //XGUI_Displayer* aDisp = myWorkshop->displayer(); + //aDisp->closeLocalContexts(); + emit planeSelected(plane()); + //setSketchingMode(); + + // 8. Update sketcher actions + XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr(); + anActMgr->update(); + myWorkshop->viewer()->update(); } } @@ -147,44 +177,104 @@ void PartSet_WidgetSketchLabel::enableFocusProcessing() myLabel->installEventFilter(this); } +void PartSet_WidgetSketchLabel::storeAttributeValue() +{ +} + +void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid) +{ + // it is not necessary to save the previous plane value because the plane is chosen once + DataPtr aData = feature()->data(); + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) { + ResultPtr anEmptyResult; + GeomShapePtr anEmptyShape; + aSelAttr->setValue(anEmptyResult, anEmptyShape); + } +} + +bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + bool isOwnerSet = false; + + const TopoDS_Shape& aShape = thePrs.shape(); + std::shared_ptr aDir; + + if (thePrs.object() && (feature() != thePrs.object())) { + DataPtr aData = feature()->data(); + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) { + ResultPtr aRes = std::dynamic_pointer_cast(thePrs.object()); + if (aRes) { + GeomShapePtr aShapePtr(new GeomAPI_Shape()); + if (aShape.IsNull()) { + aShapePtr = ModelAPI_Tools::shape(aRes); + } + else { + aShapePtr->setImpl(new TopoDS_Shape(aShape)); + } + aSelAttr->setValue(aRes, aShapePtr); + isOwnerSet = true; + } + } + } + else if (!aShape.IsNull()) { + aDir = setSketchPlane(aShape); + isOwnerSet = aDir; + } + return isOwnerSet; +} + void PartSet_WidgetSketchLabel::activateCustom() { std::shared_ptr aPlane = plane(); - if (aPlane) { + bool aBodyIsVisualized = false; + XGUI_Displayer* aDisp = myWorkshop->displayer(); + QObjectPtrList aDisplayed = aDisp->displayedObjects(); + foreach (ObjectPtr anObj, aDisplayed) { + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (aResult.get() != NULL) { + aBodyIsVisualized = aResult->groupName() == ModelAPI_ResultBody::group(); + if (aBodyIsVisualized) + break; + } + } + + if (aPlane || aBodyIsVisualized) { //setSketchingMode(); // In order to avoid Opening/Closing of context too often - mySelectionTimer->start(20); + // it can be useful for a delay on the property panel filling + // it is possible that it is not necessary anymore, but it requires a check + //mySelectionTimer->start(20); + //setSketchingMode(); } else { // We have to select a plane before any operation showPreviewPlanes(); - - XGUI_Displayer* aDisp = myWorkshop->displayer(); - //aDisp->openLocalContext(); - //aDisp->activateObjects(QIntList()); - if (myFaceFilter.IsNull()) - myFaceFilter = new StdSelect_FaceFilter(StdSelect_Plane); - aDisp->addSelectionFilter(myFaceFilter); - QIntList aModes; - aModes << TopAbs_FACE; - aDisp->activateObjects(aModes); - - myLabel->setText(myText); - myLabel->setToolTip(myTooltip); - - connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onPlaneSelected())); - aDisp->updateViewer(); } + QIntList aModes; + aModes << TopAbs_FACE; + aDisp->activateObjects(aModes); + + myLabel->setText(myText); + myLabel->setToolTip(myTooltip); + + connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + activateFilters(myWorkshop->module()->workshop(), true); + + aDisp->updateViewer(); } void PartSet_WidgetSketchLabel::deactivate() { // Do not set selection mode if the widget was activated for a small moment - mySelectionTimer->stop(); - XGUI_Displayer* aDisp = myWorkshop->displayer(); - aDisp->removeSelectionFilter(myFaceFilter); - //aDisp->removeSelectionFilter(mySketchFilter); + //mySelectionTimer->stop(); + //XGUI_Displayer* aDisp = myWorkshop->displayer(); //aDisp->closeLocalContexts(); erasePreviewPlanes(); + activateFilters(myWorkshop->module()->workshop(), false); } void PartSet_WidgetSketchLabel::erasePreviewPlanes() @@ -292,7 +382,7 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Top } -void PartSet_WidgetSketchLabel::setSketchingMode() +/*void PartSet_WidgetSketchLabel::setSketchingMode() { XGUI_Displayer* aDisp = myWorkshop->displayer(); // Clear standard selection modes if they are defined @@ -300,11 +390,19 @@ void PartSet_WidgetSketchLabel::setSketchingMode() //aDisp->openLocalContext(); // Get default selection modes + QIntList aModes; - aModes.append(AIS_DSM_Text); - aModes.append(AIS_DSM_Line); + aModes.append(SketcherPrs_Tools::Sel_Dimension_Text); + aModes.append(SketcherPrs_Tools::Sel_Dimension_Line); + aModes.append(SketcherPrs_Tools::Sel_Constraint); aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); aDisp->activateObjects(aModes); +}*/ + +void PartSet_WidgetSketchLabel::showConstraints(bool theOn) +{ + myShowConstraints->setChecked(theOn); + emit showConstraintToggled(theOn); }