#include <PartSet_Module.h>
#include <PartSet_OperationSketch.h>
#include <PartSet_OperationFeatureCreate.h>
-#include <PartSet_OperationFeatureEditMulti.h>
#include <PartSet_OperationFeatureEdit.h>
#include <PartSet_Listener.h>
#include <PartSet_TestOCC.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Displayer.h>
#include <XGUI_Tools.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
#include <AIS_Shape.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
-#include <StdSelect_FaceFilter.hxx>
#include <StdSelect_TypeOfFace.hxx>
#include <QObject>
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*)), this,
- SLOT(onMouseReleased(QMouseEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
- SLOT(onMouseMoved(QMouseEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
- SLOT(onKeyRelease(QKeyEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
- SLOT(onMouseDoubleClick(QMouseEvent*)));
-
- myDocumentShapeFilter = new XGUI_ShapeDocumentFilter(aXWshop->displayer());
}
PartSet_Module::~PartSet_Module()
void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
{
+ XGUI_Workshop* aXWshp = xWorkshop();
+ XGUI_Displayer* aDisplayer = aXWshp->displayer();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
if (aPreviewOp) {
- XGUI_Workshop* aXWshp = xWorkshop();
XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
- XGUI_Displayer* aDisplayer = aXWshp->displayer();
- aDisplayer->openLocalContext();
- aDisplayer->deactivateObjectsOutOfContext();
- } else {
- Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
- aAIS->AddFilter(myDocumentShapeFilter);
+ //aDisplayer->deactivateObjectsOutOfContext();
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ if (aSketchOp->isEditOperation()) {
+ setSketchingMode(getSketchPlane(aSketchOp->feature()));
+ } else {
+ aDisplayer->openLocalContext();
+ aDisplayer->activateObjectsOutOfContext(QIntList());
+ myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
+ aDisplayer->addSelectionFilter(myPlaneFilter);
+ QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
+ aDisplayer->setSelectionModes(aModes);
+ }
+ }
}
}
if (!theOperation)
return;
XGUI_Workshop* aXWshp = xWorkshop();
+ XGUI_Displayer* aDisplayer = aXWshp->displayer();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
if (aPreviewOp) {
XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
- } else {
- // Activate results of current feature for selection
- FeaturePtr aFeature = theOperation->feature();
- XGUI_Displayer* aDisplayer = aXWshp->displayer();
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- aDisplayer->activate(*aIt);
- }
- Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
- aAIS->RemoveFilter(myDocumentShapeFilter);
- }
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ aDisplayer->closeLocalContexts();
+ } else {
+ PartSet_OperationFeatureCreate* aCreationOp =
+ dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
+ if (aCreationOp) {
+ // Activate just created object for selection
+ FeaturePtr aFeature = aCreationOp->feature();
+ QIntList aModes = sketchSelectionModes(aFeature);
+ const std::list<ResultPtr>& aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
+ for (anIt = aResults.begin(); anIt != aLast; anIt++) {
+ aDisplayer->activate(*anIt, aModes);
+ }
+ aDisplayer->activate(aFeature, aModes);
+ aDisplayer->clearSelected();
+ }
+ }
+ }// else {
+ // Activate results of current feature for selection
+ //FeaturePtr aFeature = theOperation->feature();
+ //XGUI_Displayer* aDisplayer = aXWshp->displayer();
+ //std::list<ResultPtr> aResults = aFeature->results();
+ //std::list<ResultPtr>::const_iterator aIt;
+ //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ // aDisplayer->activate(*aIt);
+ //}
+ //}
}
void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
XGUI_Workshop* aXWshp = xWorkshop();
PartSet_OperationSketchBase* aPreviewOp =
dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
- Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
- if (aPreviewOp && (!aView.IsNull())) {
+ if (aPreviewOp) {
ModuleBase_ISelection* aSelection = workshop()->selection();
- // Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
- aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
+ aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
}
}
{
PartSet_OperationSketchBase* aPreviewOp =
dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
- Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
- if (aPreviewOp && (!aView.IsNull())) {
+ if (aPreviewOp) {
ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
- aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
+ aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
}
}
{
PartSet_OperationSketchBase* aPreviewOp =
dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
- Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
- if (aPreviewOp && (!aView.IsNull()))
- aPreviewOp->mouseMoved(theEvent, aView);
+ if (aPreviewOp)
+ aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
}
void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
if (aPreviewOp && (!aView.IsNull())) {
ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
+ aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
}
}
void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
{
- //erasePlanes();
myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
- xWorkshop()->actionsMgr()->update();
+}
- //PartSet_TestOCC::testSelection(myWorkshop);
+void PartSet_Module::onSketchLaunched()
+{
+ xWorkshop()->actionsMgr()->update();
+ // Set working plane
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ FeaturePtr aSketch = anOperation->feature();
+ setSketchingMode(getSketchPlane(aSketch));
}
void PartSet_Module::onFitAllView()
}
ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- aSketchOp->initSelection(aSelected, aHighlighted);
- } else if (aFeature) {
+ aSketchOp->initSelection(aSelection, myWorkshop->viewer());
+ } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
anOperation->setFeature(aFeature);
- //Deactivate result of current feature in order to avoid its selection
+ ////Deactivate result of current feature in order to avoid its selection
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
std::list<ResultPtr> aResults = aFeature->results();
std::list<ResultPtr>::const_iterator aIt;
void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
{
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- if (!isStop) {
- foreach(ObjectPtr aObject, theFeatures)
- {
- activateFeature(aObject, false);
- }
- }
+ //if (!isStop) {
+ // foreach(ObjectPtr aObject, theFeatures) {
+ // activateFeature(aObject);
+ // }
+ //}
aDisplayer->stopSelection(theFeatures, isStop, false);
ModuleBase_IViewer* aViewer = myWorkshop->viewer();
aDisplayer->updateViewer();
}
-void PartSet_Module::onCloseLocalContext()
+void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
{
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- aDisplayer->deactivateObjectsOutOfContext();
- aDisplayer->closeLocalContexts();
+ if (!myPlaneFilter.IsNull()) {
+ aDisplayer->removeSelectionFilter(myPlaneFilter);
+ myPlaneFilter.Nullify();
+ }
+ QIntList aModes;
+ // Clear standard selection modes
+ aDisplayer->setSelectionModes(aModes);
+ aDisplayer->openLocalContext();
+
+ // Set filter
+ mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
+ aDisplayer->addSelectionFilter(mySketchFilter);
+
+ // Get default selection modes
+ aModes = sketchSelectionModes(ObjectPtr());
+ aDisplayer->activateObjectsOutOfContext(aModes);
}
void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
if (aPrevOp) {
std::list<FeaturePtr> aList = aPrevOp->subFeatures();
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+ QIntList aModes = sketchSelectionModes(aPrevOp->feature());
std::list<FeaturePtr>::iterator aSFIt;
for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
std::list<ResultPtr> aResults = (*aSFIt)->results();
std::list<ResultPtr>::iterator aIt;
for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
- if (isDisplay)
- aDisplayer->activateInLocalContext((*aIt), aModes, false);
- else
+ if (!isDisplay)
aDisplayer->erase((*aIt), false);
}
if (!isDisplay)
aDisplayer->erase((*aSFIt), false);
}
- aDisplayer->deactivateObjectsOutOfContext();
+ //aDisplayer->deactivateObjectsOutOfContext();
}
if (isDisplay)
ModelAPI_EventCreator::get()->sendUpdated(
anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
} else {
ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
- FeaturePtr aSketch;
+ CompositeFeaturePtr aSketch;
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp) {
aSketch = aPrevOp->sketch();
}
if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
- } else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) {
- anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
} else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
}
SLOT(onFeatureConstructed(ObjectPtr, int)));
connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
SLOT(onRestartOperation(std::string, ObjectPtr)));
- connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
- SLOT(onMultiSelectionEnabled(bool)));
+ // If manage multi selection the it will be impossible to select more then one
+ // object under operation Edit
+// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
+// SLOT(onMultiSelectionEnabled(bool)));
connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
SLOT(onSetSelection(const QList<ObjectPtr>&)));
- connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext()));
-
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
SLOT(onPlaneSelected(double, double, double)));
connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
+ connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
}
}
return anOperation;
}
-//void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
-//{
-// static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
-// boost::shared_ptr<Config_PointerMessage> aMessage =
-// boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
-// aMessage->setPointer(theOperation);
-// Events_Loop::loop()->send(aMessage);
-//}
-
-void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
-{
- ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
- XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
- aDisplayer->activateInLocalContext(theFeature, aModes, isUpdateViewer);
-
- // If this is a Sketcher then activate objects (planar faces) outside of context
- PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
- if (aSketchOp) {
- Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane);
- aDisplayer->activateObjectsOutOfContext(aModes, aFilter);
- } else {
- aDisplayer->deactivateObjectsOutOfContext();
- }
- }
-}
void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
{
aDisplayer->erase(*aIt, false);
std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
- std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
for (; anIt != aLast; anIt++) {
std::list<ResultPtr>::const_iterator aRIt;
for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
aDisplayer->display((*aRIt), false);
- aDisplayer->activateInLocalContext((*aRIt), aModes, false);
+ aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
}
aDisplayer->display(aSPFeature, false);
- aDisplayer->activateInLocalContext(aSPFeature, aModes, false);
+ aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
}
aDisplayer->updateViewer();
}
return aConnector->workshop();
}
return 0;
-}
\ No newline at end of file
+}
+
+
+QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
+{
+ QIntList aModes;
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+ if (aFeature) {
+ if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
+ aModes.append(TopAbs_FACE);
+ return aModes;
+ } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
+ aModes.append(AIS_DSM_Text);
+ aModes.append(AIS_DSM_Line);
+ return aModes;
+ }
+ }
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+ return aModes;
+}
+
+
+gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
+{
+ DataPtr aData = theSketch->data();
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ boost::shared_ptr<GeomDataAPI_Dir> aNorm = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
+ gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
+ return gp_Pln(aOrig, aDir);
+}
+
+
+void PartSet_Module::onSelectionChanged()
+{
+ ModuleBase_ISelection* aSelect = myWorkshop->selection();
+ QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
+ // We need to stop edit operation if selection is cleared
+ if (aSelected.size() == 0) {
+ // do not perform commit of the current edit operation here, because
+ // this functionality is realized inside this operation
+ /*PartSet_OperationFeatureEdit* anEditOp =
+ dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
+ if (!anEditOp)
+ return;
+ anEditOp->commit();*/
+ } else {
+ PartSet_OperationSketchBase* aSketchOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+ if (aSketchOp) {
+ aSketchOp->selectionChanged(aSelect);
+ }
+ }
+}