X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetSketchCreator.cpp;h=f31198234f3d9be6d5d423019c3021f3522d811f;hb=3f9cf46387aced1e032add4fe903b7d3ef72edc2;hp=ade61b33434f21edda95113fedde058b49ce0eb5;hpb=7fce531950fca3796b798b234c4b64ef1c2edc43;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index ade61b334..f31198234 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetSketchCreator.cpp -// Created: 08 June 2015 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-2017 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 "PartSet_WidgetSketchCreator.h" #include "PartSet_Module.h" @@ -22,6 +36,8 @@ #include +#include + #include #include #include @@ -45,6 +61,7 @@ #include #include +#include //#include #include #include @@ -52,7 +69,7 @@ #define DEBUG_UNDO_INVALID_SKETCH -PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, +PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData) : ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData), @@ -69,8 +86,22 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + // Size of the View control + mySizeOfViewWidget = new QWidget(this); + QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget); + aSizeLayout->addWidget(new QLabel("Size of the view", mySizeOfViewWidget)); + mySizeOfView = new QLineEdit(mySizeOfViewWidget); + + QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView); + aValidator->setLocale(ModuleBase_Tools::doubleLocale()); + aValidator->setNotation(QDoubleValidator::StandardNotation); + mySizeOfView->setValidator(aValidator); + aSizeLayout->addWidget(mySizeOfView); + myLabel = new QLabel(aLabelText, this); myLabel->setWordWrap(true); + + aLayout->addWidget(mySizeOfViewWidget); aLayout->addWidget(myLabel); aLayout->addStretch(1); @@ -99,7 +130,7 @@ bool PartSet_WidgetSketchCreator::restoreValueCustom() return true; } -bool PartSet_WidgetSketchCreator::storeValueCustom() const +bool PartSet_WidgetSketchCreator::storeValueCustom() { return true; } @@ -164,6 +195,10 @@ bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_Viewer void PartSet_WidgetSketchCreator::activateSelectionControl() { + // reset previously set size of view needed on restart extrusion after Sketch + if (myModule->sketchMgr()->previewSketchPlane()->isUseSizeOfView()) + myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(0, false); + // we need to call activate here as the widget has no focus accepted controls // if these controls are added here, activate will happens automatically after focusIn() XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); @@ -195,10 +230,16 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec if (theSelectionControl) { bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop); - if (!aBodyIsVisualized) { + bool aSketchIsVisualized = myPreviewPlanes->hasVisualizedSketch(myWorkshop); + if (!aBodyIsVisualized && !aSketchIsVisualized) { // We have to select a plane before any operation myPreviewPlanes->showPreviewPlanes(myWorkshop); + mySizeOfViewWidget->setVisible(true); + } + else { + mySizeOfViewWidget->setVisible(false); } + } else { bool aHidePreview = myPreviewPlanes->isPreviewDisplayed(); myPreviewPlanes->erasePreviewPlanes(myWorkshop); @@ -207,7 +248,7 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec } } -QIntList PartSet_WidgetSketchCreator::getShapeTypes() const +QIntList PartSet_WidgetSketchCreator::shapeTypes() const { QIntList aShapeTypes; foreach(QString aType, myShapeTypes) { @@ -262,7 +303,8 @@ bool PartSet_WidgetSketchCreator::setSelection(QList& t bool aDone = false; if (!startSketchOperation(theValues)) { myIsCustomAttribute = true; - QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); + QList::const_iterator + anIt = theValues.begin(), aLast = theValues.end(); bool aProcessed = false; for (; anIt != aLast; anIt++) { ModuleBase_ViewerPrsPtr aValue = *anIt; @@ -275,7 +317,8 @@ bool PartSet_WidgetSketchCreator::setSelection(QList& t emit valuesChanged(); updateObject(myFeature); setVisibleSelectionControl(false); - // manually deactivation because the widget was not activated as has no focus acceptin controls + // manually deactivation because the widget was + // not activated as has no focus acceptin controls deactivate(); emit focusOutWidget(this); } @@ -295,7 +338,8 @@ void PartSet_WidgetSketchCreator::updateOnSelectionChanged(const bool theDone) { } -bool PartSet_WidgetSketchCreator::startSketchOperation(const QList& theValues) +bool PartSet_WidgetSketchCreator::startSketchOperation( + const QList& theValues) { bool aSketchStarted = false; @@ -310,19 +354,35 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QListshape().get() && aResult->shape()->isEqual(aValue->shape())) { - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aResult); + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aResult); if (!aConstruction.get() || !aConstruction->isInfinite()) return aSketchStarted; } aSketchStarted = true; - + // Set View size if a plane is selected + if (myPreviewPlanes->isPreviewDisplayed() && + myPreviewPlanes->isPreviewShape(aValue->shape())) { + // set default plane size + bool isSetSizeOfView = false; + double aSizeOfView = 0; + QString aSizeOfViewStr = mySizeOfView->text(); + if (!aSizeOfViewStr.isEmpty()) { + aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView); + if (isSetSizeOfView && aSizeOfView <= 0) { + isSetSizeOfView = false; + } + } + if (isSetSizeOfView) + myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true); + } // manually deactivation because the widget was not activated as has no focus acceptin controls deactivate(); bool aHidePreview = myPreviewPlanes->isPreviewDisplayed(); myPreviewPlanes->erasePreviewPlanes(myWorkshop); // Launch Sketch operation - CompositeFeaturePtr aCompFeature = + CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); // start edit operation for the sketch @@ -332,7 +392,7 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QListsetPreselection(aValues); - myModule->sendOperation(aFOperation); + myWorkshop->processLaunchOperation(aFOperation); return aSketchStarted; } @@ -347,7 +407,8 @@ bool PartSet_WidgetSketchCreator::focusTo() return true; } else - connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); + connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), + SLOT(onResumed(ModuleBase_Operation*))); return true; } @@ -378,7 +439,7 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) // Validate the created sketch. If it is valid, it is set into the composite feature selection // list, otherwise it is removed - CompositeFeaturePtr aCompFeature = + CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); if (aCompFeature->numberOfSubs() > 0) { @@ -397,13 +458,13 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) aMgr->startOperation("Delete invalid Sketch feature", false); // delete invalid sketch - CompositeFeaturePtr aSketchFeature = + CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast(aCompFeature->subFeature(0)); QObjectPtrList anObjects; anObjects.append(aSketchFeature); XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); - aWorkshop->deleteFeatures(anObjects, std::set()); + aWorkshop->deleteFeatures(anObjects); aMgr->finishOperation(); #endif @@ -422,15 +483,22 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) // Update value in attribute selection list XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); - XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); - const QList& aWidgets = aPanel->modelWidgets(); + XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel(); + const QList& aWidgets = aPropertyPanel->modelWidgets(); + ModuleBase_ModelWidget* aListWidget = 0; foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { - if (aWidget->attributeID() == myAttributeListID) - aWidget->restoreValue(); + if (aWidget->attributeID() == myAttributeListID) { + aListWidget = aWidget; + break; + } + } + if (aListWidget) { + aListWidget->restoreValue(); + aPropertyPanel->activateNextWidget(aListWidget); } // Hide sketcher result - CompositeFeaturePtr aSketchFeature = + CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast(aCompFeature->subFeature(0)); std::list aResults = aSketchFeature->results(); std::list::const_iterator aIt; @@ -453,7 +521,8 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute); - std::string aValidatorID, anError; + std::string aValidatorID; + Events_InfoMessage anError; aSelList->append(aRes, GeomShapePtr()); if (aFactory->validate(anAttribute, aValidatorID, anError)) updateObject(aCompFeature); @@ -471,19 +540,23 @@ bool PartSet_WidgetSketchCreator::validateSelectionList() const SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::string aValidatorID, anError; + std::string aValidatorID; + Events_InfoMessage anError; bool isValidPComposite = aFactory->validate(anAttrList, aValidatorID, anError); if (!isValidPComposite) { XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + // TODO(spo): translate QMessageBox::question(aWorkshop->desktop(), tr("Apply current feature"), - tr("Sketch is invalid and will be deleted.\nError: %1").arg(anError.c_str()), + tr("Sketch is invalid and will be deleted.\nError: %1") + .arg(anError.messageString().c_str()), QMessageBox::Ok); } return isValidPComposite; } -void PartSet_WidgetSketchCreator::setSketchObjectToList(const CompositeFeaturePtr& theCompositeFeature, - const AttributePtr& theAttribute) +void PartSet_WidgetSketchCreator::setSketchObjectToList( + const CompositeFeaturePtr& theCompositeFeature, + const AttributePtr& theAttribute) { if (!theCompositeFeature.get() || theCompositeFeature->numberOfSubs() != 1) return; @@ -500,7 +573,8 @@ void PartSet_WidgetSketchCreator::setSketchObjectToList(const CompositeFeaturePt } ResultPtr aSketchRes = aSketchFeature->results().front(); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aSketchRes); if(!aConstruction.get()) { return; }