X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetSketchCreator.cpp;h=34762063035f07a42ddf357d035d7845ab6a4564;hb=04dcca50b319e65e5141be7f6c329a2e1cf94718;hp=ffccda73aacacb7621752184a65cc454b59b393c;hpb=bc040d7778dfca67e24a0452ce41f88417799adb;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index ffccda73a..347620630 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -7,27 +7,41 @@ #include "PartSet_WidgetSketchCreator.h" #include "PartSet_Module.h" +#include + #include #include #include #include +#include #include +#include +#include +#include +#include +#include + +#include +#include + #include #include #include +#include #include #include #include #include +#include PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData, const std::string& theParentId) -: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule) +: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule), myUseBody(true) { QFormLayout* aLayout = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aLayout); @@ -45,6 +59,11 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, myTextLine->setToolTip(aToolTip); myTextLine->installEventFilter(this); + QString aUseBody = QString::fromStdString(theData->getProperty(USE_BODY)); + if(!aUseBody.isEmpty()) { + myUseBody = QVariant(aUseBody).toBool(); + } + aLayout->addRow(myLabel, myTextLine); } @@ -59,8 +78,14 @@ QList PartSet_WidgetSketchCreator::getControls() const return aControls; } -bool PartSet_WidgetSketchCreator::restoreValue() +bool PartSet_WidgetSketchCreator::restoreValueCustom() { + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(myFeature); + if (aCompFeature->numberOfSubs() > 0) { + FeaturePtr aSubFeature = aCompFeature->subFeature(0); + myTextLine->setText(QString::fromStdString(aSubFeature->data()->name())); + } return true; } @@ -71,57 +96,126 @@ bool PartSet_WidgetSketchCreator::storeValueCustom() const void PartSet_WidgetSketchCreator::activateCustom() { - connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted())); - - - //XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); - //XGUI_Workshop* aWorkshop = aConnector->workshop(); - //XGUI_Displayer* aDisp = aWorkshop->displayer(); - - //QIntList aModes; - //aModes << TopAbs_FACE; - //aDisp->activateObjects(aModes); - // - //connect(aWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - //activateFilters(myModule->workshop(), true); + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(myFeature); + if (aCompFeature->numberOfSubs() == 0) + connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted())); } void PartSet_WidgetSketchCreator::onStarted() { disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted())); - CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); - FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); - - ModuleBase_Operation* anOperation = myModule->createOperation("Sketch"); - anOperation->setFeature(aSketch); - myModule->sendOperation(anOperation); + // Check that model already has bodies + XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_Displayer* aDisp = aWorkshop->displayer(); + QObjectPtrList aObjList = aDisp->displayedObjects(); + bool aHasBody = !myUseBody; + ResultBodyPtr aBody; + if(!aHasBody) { + foreach(ObjectPtr aObj, aObjList) { + aBody = std::dynamic_pointer_cast(aObj); + if (aBody.get() != NULL) { + aHasBody = true; + break; + } + } + } + + if (aHasBody) { + // Launch Sketch operation + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(myFeature); + FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); + + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (myModule->createOperation("Sketch")); + if (aFOperation) + aFOperation->setFeature(aSketch); + myModule->sendOperation(aFOperation); + //connect(anOperation, SIGNAL(aborted()), aWorkshop->operationMgr(), SLOT(abortAllOperations())); + } else { + // Break current operation + std::string anOperationName = feature()->getKind(); + QString aTitle = tr( anOperationName.c_str() ); + QMessageBox::warning(this, aTitle, + tr("There are no bodies found. Operation aborted."), QMessageBox::Ok); + ModuleBase_Operation* aOp = myModule->workshop()->currentOperation(); + aOp->abort(); + } } -void PartSet_WidgetSketchCreator::storeAttributeValue() +bool PartSet_WidgetSketchCreator::focusTo() { -} - -void PartSet_WidgetSketchCreator::restoreAttributeValue(const bool theValid) -{ -} - -bool PartSet_WidgetSketchCreator::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - std::shared_ptr aFace(new GeomAPI_Face()); - aFace->setImpl(new TopoDS_Shape(thePrs.shape())); - if (aFace->isPlanar()) - return true; - //CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); - //FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); - - //ModuleBase_Operation* anOperation = myModule->createOperation("Sketch"); - //anOperation->setFeature(aSketch); - //myModule->sendOperation(anOperation); + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(myFeature); + if (aCompFeature->numberOfSubs() == 0) + return ModuleBase_ModelWidget::focusTo(); + + connect(myModule, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); + SessionPtr aMgr = ModelAPI_Session::get(); + // Open transaction that is general for the previous nested one: it will be closed on nested commit + bool aIsOp = aMgr->isOperation(); + if (!aIsOp) { + const static std::string aNestedOpID("Parameters modification"); + aMgr->startOperation(aNestedOpID, true); + } + + restoreValue(); return false; } -bool PartSet_WidgetSketchCreator::setSelection(const QList& theValues, int& thePosition) +void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) { - return true; -} \ No newline at end of file + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(myFeature); + CompositeFeaturePtr aSketchFeature = + std::dynamic_pointer_cast(aCompFeature->subFeature(0)); + if (aSketchFeature->numberOfSubs() == 0) { + // Abort operation + SessionPtr aMgr = ModelAPI_Session::get(); + // Close transaction + /* + bool aIsOp = aMgr->isOperation(); + if (aIsOp) { + const static std::string aNestedOpID("Parameters cancelation"); + aMgr->startOperation(aNestedOpID, true); + } + */ + theOp->abort(); + } else { + // Hide sketcher result + std::list aResults = aSketchFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + (*aIt)->setDisplayed(false); + } + aSketchFeature->setDisplayed(false); + + if(myUseBody) { + // Add Selected body were created the sketcher to list of selected objects + DataPtr aData = aSketchFeature->data(); + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr.get()) { + ResultPtr aRes = aSelAttr->context(); + GeomShapePtr aShape = aSelAttr->value(); + if (aRes.get()) { + std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute); + std::string aValidatorID, anError; + AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute); + aSelList->append(aRes, GeomShapePtr()); + if (aFactory->validate(anAttribute, aValidatorID, anError)) + updateObject(aCompFeature); + else + aSelList->clear(); + } + } + } + } +}