X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Module.cpp;h=99cab29e5c2a2be1f1c3660db3f475f92ec16c61;hb=2e3e7b15bec99425564665f1e58fa8c013b6ec3c;hp=d77c02df5a5fd8f0dd339123b9de6bf492ac3915;hpb=741c81c48a9621a02f92507824d383431ac7af68;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d77c02df5..99cab29e5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -5,9 +5,10 @@ #include #include #include -#include +#include #include +#include #include #include @@ -18,6 +19,9 @@ #include #include #include +#include +#include +#include #include #include @@ -38,7 +42,6 @@ #include #endif - /*!Create and return new instance of XGUI_Module*/ extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop) { @@ -52,11 +55,16 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); + connect(anOperationMgr, SIGNAL(operationStarted()), + this, SLOT(onOperationStarted())); + connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); - connect(myWorkshop->selector(), SIGNAL(selectionChanged()), - this, SLOT(onSelectionChanged())); + XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr(); + connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), + this, SLOT(onContextMenuCommand(const QString&, bool))); + connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this, SLOT(onMousePressed(QMouseEvent*))); connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), @@ -83,9 +91,9 @@ void PartSet_Module::createFeatures() myFeaturesInFiles = aXMLReader.featuresInFiles(); } -void PartSet_Module::featureCreated(XGUI_Command* theFeature) +void PartSet_Module::featureCreated(QAction* theFeature) { - theFeature->connectTo(this, SLOT(onFeatureTriggered())); + connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered())); } QStringList PartSet_Module::nestedFeatures(QString) @@ -103,11 +111,16 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId) */ void PartSet_Module::onFeatureTriggered() { - XGUI_Command* aCmd = dynamic_cast(sender()); + //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(), + // myWorkshop->viewer()->activeView()); + + //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(), + // myWorkshop->viewer()->activeView()); + QAction* aCmd = dynamic_cast(sender()); //Do nothing on uncheck if(aCmd->isCheckable() && !aCmd->isChecked()) return; - launchOperation(aCmd->id()); + launchOperation(aCmd->data().toString()); } void PartSet_Module::launchOperation(const QString& theCmdId) @@ -116,31 +129,34 @@ void PartSet_Module::launchOperation(const QString& theCmdId) sendOperation(anOperation); } +void PartSet_Module::onOperationStarted() +{ + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( + myWorkshop->operationMgr()->currentOperation()); + if (aPreviewOp) { + XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel(); + connect(aPreviewOp, SIGNAL(focusActivated(const std::string&)), + aPropPanel, SLOT(onFocusActivated(const std::string&))); + } +} + void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) { if (!theOperation) return; PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); + if (aPreviewOp) { + XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel(); + disconnect(aPreviewOp, SIGNAL(focusActivated(const std::string&)), + aPropPanel, SLOT(onFocusActivated(const std::string&))); + } } -void PartSet_Module::onSelectionChanged() +void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked) { - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - XGUI_SelectionMgr* aSelector = myWorkshop->selector(); - if (aSelector) { - NCollection_List aList; - aSelector->selectedShapes(aList); - - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - boost::shared_ptr aFeature; - // only first selected shape is processed - if (!aList.IsEmpty()) { - aFeature = aDisplayer->GetFeature(aList.First()); - } - aPreviewOp->setSelected(aFeature, !aList.IsEmpty() ? aList.First() : TopoDS_Shape()); - } + QFeatureList aFeatures = myWorkshop->selector()->selectedFeatures(); + if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) { + editFeature(aFeatures.first()); } } @@ -150,9 +166,11 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), - myWorkshop->viewer()->activeView()); - aPreviewOp->mousePressed(aPnt, theEvent); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + std::list aSelected = aDisplayer->GetSelected(); + std::list aHighlighted = aDisplayer->GetHighlighted(); + + aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } } @@ -162,9 +180,11 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), - myWorkshop->viewer()->activeView()); - aPreviewOp->mouseReleased(aPnt, theEvent); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + std::list aSelected = aDisplayer->GetSelected(); + std::list aHighlighted = aDisplayer->GetHighlighted(); + + aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } } @@ -173,11 +193,7 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) - { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), - myWorkshop->viewer()->activeView()); - aPreviewOp->mouseMoved(aPnt, theEvent); - } + aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView()); } void PartSet_Module::onKeyRelease(QKeyEvent* theEvent) @@ -192,16 +208,14 @@ void PartSet_Module::onKeyRelease(QKeyEvent* theEvent) void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) { myWorkshop->viewer()->setViewProjection(theX, theY, theZ); + myWorkshop->actionsMgr()->update(); - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - if (anOperation) { - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - visualizePreview(aPreviewOp->feature(), false); - } - } + //PartSet_TestOCC::testSelection(myWorkshop); +} - myWorkshop->actionsMgr()->setNestedActionsEnabled(true); +void PartSet_Module::onFitAllView() +{ + myWorkshop->viewer()->fitAll(); } void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr theFeature) @@ -210,17 +224,81 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr(anOperation); if (aPreviewOp) { - aPreviewOp->init(theFeature); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + // refill the features list with avoiding of the features, obtained only by vertex shape (TODO) + std::list aSelected = aDisplayer->GetSelected(TopAbs_VERTEX); + std::list aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX); + aPreviewOp->init(theFeature, aSelected, aHighlighted); } - myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true); sendOperation(anOperation); + myWorkshop->actionsMgr()->updateCheckState(); +} + +void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) +{ + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + aViewer->enableMultiselection(theEnabled); +} + +void PartSet_Module::onStopSelection(const std::list& theFeatures, const bool isStop) +{ + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + if (!isStop) { + std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); + boost::shared_ptr aFeature; + for (; anIt != aLast; anIt++) { + activateFeature((*anIt).feature(), false); + } + } + aDisplayer->StopSelection(theFeatures, isStop, false); + + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + aViewer->enableSelection(!isStop); + + aDisplayer->UpdateViewer(); +} + +void PartSet_Module::onSetSelection(const std::list& theFeatures) +{ + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->SetSelected(theFeatures, false); + aDisplayer->UpdateViewer(); +} + +void PartSet_Module::onCloseLocalContext() +{ + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->CloseLocalContexts(); } void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, int theMode) { - bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort; - visualizePreview(theFeature, isDisplay); + bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; + visualizePreview(theFeature, isDisplay, false); + if (!isDisplay) { + ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); + boost::shared_ptr aSketch; + PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); + if (aPrevOp) { + std::map, boost::shared_ptr > + aList = aPrevOp->subPreview(); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + std::list aModes = aPrevOp->getSelectionModes(aPrevOp->feature()); + + std::map, boost::shared_ptr >::const_iterator + anIt = aList.begin(), aLast = aList.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = (*anIt).first; + visualizePreview(aFeature, false, false); + } + aDisplayer->UpdateViewer(); + } + } + + if (theMode == PartSet_OperationSketchBase::FM_Activation || + theMode == PartSet_OperationSketchBase::FM_Deactivation) + activateFeature(theFeature, true); } ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId) @@ -243,13 +321,14 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI else if(theCmdId == PartSet_OperationSketchLine::Type() || theCmdId == PartSet_OperationEditLine::Type()) { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); - boost::shared_ptr aSketchFeature; - if (aCurOperation) - aSketchFeature = aCurOperation->feature(); + boost::shared_ptr aSketch; + PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); + if (aPrevOp) + aSketch = aPrevOp->sketch(); if (theCmdId == PartSet_OperationSketchLine::Type()) - anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature); + anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch); else - anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature); + anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch); } else { anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); @@ -264,13 +343,28 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI this, SLOT(onFeatureConstructed(boost::shared_ptr, int))); connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr)), this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); + connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), + this, SLOT(onMultiSelectionEnabled(bool))); + + connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), + this, SLOT(onMultiSelectionEnabled(bool))); + connect(aPreviewOp, SIGNAL(stopSelection(const std::list&, const bool)), + this, SLOT(onStopSelection(const std::list&, const bool))); + connect(aPreviewOp, SIGNAL(setSelection(const std::list&)), + this, SLOT(onSetSelection(const std::list&))); + + connect(aPreviewOp, SIGNAL(closeLocalContext()), + this, SLOT(onCloseLocalContext())); PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this, SLOT(onPlaneSelected(double, double, double))); + connect(aSketchOp, SIGNAL(fitAllView()), + this, SLOT(onFitAllView())); } } + return anOperation; } @@ -283,7 +377,8 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation) Events_Loop::loop()->send(aMessage); } -void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay) +void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay, + const bool isUpdateViewer) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); if (!anOperation) @@ -296,12 +391,74 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); - aDisplayer->RedisplayInLocalContext(theFeature, - aPreview ? aPreview->impl() : TopoDS_Shape(), - aPreviewOp->getSelectionModes(theFeature)); + aDisplayer->Redisplay(theFeature, + aPreview ? aPreview->impl() : TopoDS_Shape(), false); } - else { - //aDisplayer->CloseLocalContexts(false); - aDisplayer->Erase(anOperation->feature()); + else + aDisplayer->Erase(theFeature, false); + + if (isUpdateViewer) + aDisplayer->UpdateViewer(); +} + +void PartSet_Module::activateFeature(boost::shared_ptr theFeature, + const bool isUpdateViewer) +{ + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) { + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature), + isUpdateViewer); + } +} + +void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) +{ + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); + if (!anOperation) + return; + + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (!aPreviewOp) + return; + + boost::shared_ptr aFeature = aPreviewOp->feature(); + if (!aFeature || aFeature->getKind() != theCmdId) + return; + + std::map, boost::shared_ptr > + aList = aPreviewOp->subPreview(); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + std::list aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature()); + + std::map, boost::shared_ptr >::const_iterator + anIt = aList.begin(), aLast = aList.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = (*anIt).first; + boost::shared_ptr aPreview = (*anIt).second; + aDisplayer->Redisplay(aFeature, + aPreview ? aPreview->impl() : TopoDS_Shape(), false); + aDisplayer->ActivateInLocalContext(aFeature, aModes, false); + } + aDisplayer->UpdateViewer(); +} + +void PartSet_Module::editFeature(FeaturePtr theFeature) +{ + if (!theFeature) + return; + + if (theFeature->getKind() == "Sketch") { + FeaturePtr aFeature = theFeature; + if (XGUI_Tools::isModelObject(aFeature)) { + ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); + aFeature = aObject->featureRef(); + } + + if (aFeature) { + onLaunchOperation(aFeature->getKind(), aFeature); + updateCurrentPreview(aFeature->getKind()); + } } }