From d02bf05eb5f3c3da6ff595b34658034996a6869f Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 24 Apr 2014 18:07:46 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Set plane for sketch and erase the sketch preview. --- src/PartSet/CMakeLists.txt | 3 +- src/PartSet/PartSet_Module.cpp | 8 ++--- src/PartSet/PartSet_OperationSketch.cpp | 36 +++++++++++++---------- src/PartSet/PartSet_OperationSketch.h | 4 +-- src/PartSet/PartSet_OperationSketchBase.h | 5 ++-- src/XGUI/XGUI_Displayer.cpp | 32 ++++++++++++++++++-- src/XGUI/XGUI_Displayer.h | 10 +++++-- src/XGUI/XGUI_Viewer.cpp | 11 +++++++ src/XGUI/XGUI_Viewer.h | 6 ++++ src/XGUI/XGUI_Workshop.cpp | 15 +++++++--- 10 files changed, 96 insertions(+), 34 deletions(-) diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 260da21aa..45abe7d5b 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -47,6 +47,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/Events ${CMAKE_SOURCE_DIR}/src/ModuleBase ${CMAKE_SOURCE_DIR}/src/ModelAPI + ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI ${CMAKE_SOURCE_DIR}/src/SketchPlugin ${CMAKE_SOURCE_DIR}/src/GeomAPI ${CAS_INCLUDE_DIRS} @@ -62,7 +63,7 @@ ADD_LIBRARY(PartSet SHARED ) # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore -TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI) +TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI GeomAlgoAPI) ADD_DEPENDENCIES(PartSet ModuleBase) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e0d4d32b9..f1787442a 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -119,9 +119,9 @@ void PartSet_Module::onViewSelectionChanged() if (aPreviewOp) { XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); if (aViewer) { - AIS_ListOfInteractive aList; - aViewer->getSelectedObjects(aList); - aPreviewOp->setSelectedObjects(aList); + NCollection_List aList; + aViewer->getSelectedShapes(aList); + aPreviewOp->setSelectedShapes(aList); } } } @@ -142,6 +142,6 @@ void PartSet_Module::visualizePreview(bool isDisplay) } else { myWorkshop->displayer()->GlobalSelection(false); - myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview()); + myWorkshop->displayer()->Erase(anOperation->feature()); } } diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index c9608cd2e..1f1f1e91c 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -4,9 +4,10 @@ #include -#include +#include #include -#include +#include +#include #include #include @@ -37,27 +38,32 @@ int PartSet_OperationSketch::getSelectionMode() const return TopAbs_FACE; } -void PartSet_OperationSketch::setSelectedObjects(const AIS_ListOfInteractive& theList) +void PartSet_OperationSketch::setSelectedShapes(const NCollection_List& theList) { if (theList.IsEmpty()) return; - // 1. get selected fase - Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(theList.First()); - if (anAISShape.IsNull()) - return; - - const TopoDS_Shape& aShape = anAISShape->Shape(); - boost::shared_ptr aRes(new GeomAPI_Shape); - aRes->setImpl(new TopoDS_Shape(aShape)); + // get selected shape + const TopoDS_Shape& aShape = theList.First(); + boost::shared_ptr aGShape(new GeomAPI_Shape); + aGShape->setImpl(new TopoDS_Shape(aShape)); // get plane parameters - double anX = 1, anY = 0, aZ = 0, anOrigin = 0; + boost::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); // set plane parameters to feature - //boost::shared_ptr aData = feature()->data(); - //boost::shared_ptr anAttr = aData->docRef(SKETCH_ATTR_X); - //anAttr->setValue(anX); + boost::shared_ptr aData = feature()->data(); + double anA, aB, aC, aD; + aPlane->coefficients(anA, aB, aC, aD); + + boost::shared_ptr anAttr; + + aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA); + aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB); + aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC); + aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD); + + //emit viewPlaneChanged(); commit(); } diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 83be57a99..6a7670b00 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -33,8 +33,8 @@ public: virtual int getSelectionMode() const; /// Gives the current selected objects to be processed by the operation - /// \param theList a list of interactive selected objects - virtual void setSelectedObjects(const AIS_ListOfInteractive& theList); + /// \param theList a list of interactive selected shapes + virtual void setSelectedShapes(const NCollection_List& theList); }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index b6c160ae7..72a635bb1 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -8,12 +8,11 @@ #include "PartSet.h" #include +#include #include #include -class AIS_ListOfInteractive; - /*! \class PartSet_OperationSketchBase * \brief The base operation for the sketch features. @@ -39,7 +38,7 @@ public: /// Gives the current selected objects to be processed by the operation /// \param a list of interactive selected objects - virtual void setSelectedObjects(const AIS_ListOfInteractive& aList) = 0; + virtual void setSelectedShapes(const NCollection_List& theList) = 0; }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index a036e8f75..bca8d2d24 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -32,6 +33,13 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); + std::vector aDispAIS; + if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) { + aDispAIS = myFeature2AISObjectMap[theFeature]; + } + aDispAIS.push_back(anAIS); + myFeature2AISObjectMap[theFeature] = aDispAIS; + aContext->Display(anAIS, Standard_False); if (isUpdateViewer) @@ -39,10 +47,23 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, } void XGUI_Displayer::Erase(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, const bool isUpdateViewer) + const bool isUpdateViewer) { + if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end()) + return; + + std::vector aDispAIS = myFeature2AISObjectMap[theFeature]; + std::vector::const_iterator anIt = aDispAIS.begin(), + aLast = aDispAIS.end(); Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); - aContext->EraseAll(); + for (; anIt != aLast; anIt++) { + Handle(AIS_InteractiveObject) anAIS = *anIt; + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (anAISShape.IsNull()) + continue; + aContext->Erase(anAISShape); + } + if (isUpdateViewer) aContext->UpdateCurrentViewer(); } @@ -54,7 +75,14 @@ void XGUI_Displayer::LocalSelection(boost::shared_ptr theFeatu Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); + std::vector aDispAIS; + if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) { + aDispAIS = myFeature2AISObjectMap[theFeature]; + } + aDispAIS.push_back(anAIS); + myFeature2AISObjectMap[theFeature] = aDispAIS; aContext->Display(anAIS, Standard_False); + AIS_ListOfInteractive anAISList; anAISList.Append(anAIS); myViewer->setLocalSelection(anAISList, theMode, true); diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 1dc238b90..2a54cb9e4 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -11,10 +11,15 @@ #include #include +#include + +#include +#include class XGUI_Viewer; class ModelAPI_Feature; + /**\class XGUI_Displayer * \ingroup GUI * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer @@ -50,10 +55,8 @@ public: /// Erase the feature and a shape. /// \param theFeature a feature instance - /// \param theFeature a shape /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void Erase(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, - const bool isUpdateViewer = true); + void Erase(boost::shared_ptr theFeature, const bool isUpdateViewer = true); /// Deactivates selection of sub-shapes /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly @@ -61,6 +64,7 @@ public: protected: XGUI_Viewer* myViewer; ///< the viewer where the objects should be visualized + std::map, std::vector > myFeature2AISObjectMap; }; #endif diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index e6dd6e2b7..a09722bcd 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -238,6 +238,17 @@ void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList) theList.Append(myAISContext->SelectedInteractive()); } +void XGUI_Viewer::getSelectedShapes(NCollection_List& theList) +{ + Handle(AIS_InteractiveContext) ic = AISContext(); + + for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) { + TopoDS_Shape aShape = ic->SelectedShape(); + if (!aShape.IsNull()) + theList.Append(aShape); + } +} + void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList) { AIS_ListIteratorOfListOfInteractive aIt; diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index c4ae363b6..c7a2492f1 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include class XGUI_MainWindow; class QMdiSubWindow; @@ -69,6 +71,10 @@ public: /// \param theList - list to be filled with selected objects void getSelectedObjects(AIS_ListOfInteractive& theList); + /// Return shapes selected in 3D viewer + /// \param theList - list to be filled with selected shapes + void getSelectedShapes(NCollection_List& theList); + /// Selects objects in 3D viewer. Other selected objects are left as selected /// \param theList - list objects to be selected void setObjectsSelected(const AIS_ListOfInteractive& theList); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index f653683a1..cbc3ce146 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -196,11 +196,18 @@ void XGUI_Workshop::onOperationStarted() //****************************************************** void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) { - myMainWindow->hidePropertyPanel(); - updateCommandStatus(); + ModuleBase_PropPanelOperation* aOperation = + (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation()); - XGUI_MainMenu* aMenu = myMainWindow->menuObject(); - aMenu->restoreCommandState(); + if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel + updateCommandStatus(); + } else { + myMainWindow->hidePropertyPanel(); + updateCommandStatus(); + + XGUI_MainMenu* aMenu = myMainWindow->menuObject(); + aMenu->restoreCommandState(); + } } /* -- 2.39.2