#include <Events_Loop.h>
#include <Events_Message.h>
+#include <AIS_ListOfInteractive.hxx>
+
#include <QObject>
#include <QString>
connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
this, SLOT(onOperationStopped(ModuleBase_Operation*)));
+ connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+ this, SLOT(onViewSelectionChanged()));
}
PartSet_Module::~PartSet_Module()
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
- connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
- aPreviewOp, SLOT(onViewSelectionChanged()));
+ if (aPreviewOp)
visualizePreview(true);
- }
}
void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
if (!anOperation)
return;
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp)
+ visualizePreview(false);
+}
+void PartSet_Module::onViewSelectionChanged()
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
- disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
- aPreviewOp, SLOT(onViewSelectionChanged()));
- visualizePreview(false);
+ XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+ if (aViewer) {
+ AIS_ListOfInteractive aList;
+ aViewer->getSelectedObjects(aList);
+ aPreviewOp->setSelectedObjects(aList);
+ }
}
}
/// SLOT, that is called after the operation is stopped. Disconnect the sketch feature
/// from the viewer selection and show the sketch preview.
void onOperationStopped(ModuleBase_Operation* theOperation);
+ /// SLOT, that is called by the selection in the viewer is changed.
+ /// The selection is sent to the current operation if it listen the selection.
+ void onViewSelectionChanged();
private:
/// Displays or erase the current operation preview, if it has it.
#include <PartSet_OperationSketch.h>
#include <SketchPlugin_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+
+#include <AIS_Shape.hxx>
+#include <AIS_ListOfInteractive.hxx>
#ifdef _DEBUG
#include <QDebug>
{
return TopAbs_FACE;
}
+
+void PartSet_OperationSketch::setSelectedObjects(const AIS_ListOfInteractive& 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<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImpl(new TopoDS_Shape(aShape));
+
+ // get plane parameters
+ double anX = 1, anY = 0, aZ = 0, anOrigin = 0;
+
+ // set plane parameters to feature
+ //boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ //boost::shared_ptr<ModelAPI_AttributeDocRef> anAttr = aData->docRef(SKETCH_ATTR_X);
+ //anAttr->setValue(anX);
+
+ commit();
+}
/// Returns the operation local selection mode
/// \return the selection mode
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);
};
#endif
boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
return aFeature->preview()->impl<TopoDS_Shape>();
}
-
-int PartSet_OperationSketchBase::getSelectionMode() const
-{
- return 0;
-}
#include <ModuleBase_PropPanelOperation.h>
#include <QObject>
+class AIS_ListOfInteractive;
+
/*!
\class PartSet_OperationSketchBase
* \brief The base operation for the sketch features.
/// Returns the operation local selection mode
/// \return the selection mode
- virtual int getSelectionMode() const;
+ virtual int getSelectionMode() const = 0;
+
+ /// 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;
};
#endif
}
}
+void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
+{
+ theList.Clear();
+ for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
+ theList.Append(myAISContext->SelectedInteractive());
+}
+
+void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
+{
+ AIS_ListIteratorOfListOfInteractive aIt;
+ for (aIt.Initialize(theList); aIt.More(); aIt.Next())
+ myAISContext->AddOrRemoveSelected(aIt.Value(), false);
+ myAISContext->UpdateCurrentViewer();
+}
+
/*! Sets hot button
*\param theOper - hot operation
*\param theState - adding state to state map operations.
//! \param isUpdateViewer the state wether the viewer should be updated immediatelly
void setGlobalSelection(const bool isUpdateViewer);
+ /// Return objects selected in 3D viewer
+ /// \param theList - list to be filled with selected objects
+ void getSelectedObjects(AIS_ListOfInteractive& 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);
+
+ /// Select the object in 3D viewer.
+ /// \param theIO - list objects to be selected
+ void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
+
//! Trihedron 3d object shown in the viewer
Handle(AIS_Trihedron) trihedron() const
{