bool ModuleBase_IModule::canActivateSelection(const ObjectPtr& theObject) const
{
ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- return !(aOperation && (!aOperation->isEditOperation()) && aOperation->hasObject(theObject));
+ return !aOperation || !aOperation->hasObject(theObject);
}
\ No newline at end of file
/// Types has to be defined according to TopAbs_ShapeEnum
virtual void activateSubShapesSelection(const QIntList& theTypes) = 0;
+ /// Activate objects in the module selection modes(opens local context)
+ virtual void activateModuleSelectionModes() = 0;
+
/// Deactivate sub-shapes selection (closes local context)
virtual void deactivateSubShapesSelection() = 0;
/// The methiod called when widget is deactivated
virtual void deactivate();
- public slots:
-
+protected:
/// Activate or deactivate selection
void activateSelection(bool toActivate);
return mySketchMgr->canDisplayObject(theObject);
}
+bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
+{
+ bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
+
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
+ isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+ if (isSketchOp || isNestedOp) {
+ // in active sketch operation it is possible to activate operation object in selection
+ // in the edit operation, e.g. points of the line can be moved when the line is edited
+ aCanActivate = aCanActivate || anOperation->isEditOperation();
+ }
+ return aCanActivate;
+}
bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
{
/// \param theObject a model object
virtual bool canDisplayObject(const ObjectPtr& theObject) const;
+ /// Returns true if selection for the object can be activate.
+ /// For sketch operation allow the selection activation if the operation is edit, for other
+ /// operation uses the default result
+ /// \param theObject a model object
+ virtual bool canActivateSelection(const ObjectPtr& theObject) const;
+
/// Add menu atems for object browser into the given menu
/// \param theMenu a popup menu to be shown in the object browser
virtual void addObjectBrowserMenu(QMenu* theMenu) const;
void PartSet_SketcherMgr::launchEditing()
{
- // there should be activate the sketch selection mode because the edit can happens
- // by any sketch entity or consttant selected
- activateObjectsInSketchMode(true);
-
if (!myCurrentSelection.empty()) {
FeaturePtr aFeature = myCurrentSelection.begin().key();
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
myModule->editFeature(aSPFeature);
}
}
-
}
theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
theModes.append(SketcherPrs_Tools::Sel_Constraint);
- theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
- theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+ theModes.append(TopAbs_VERTEX);
+ theModes.append(TopAbs_EDGE);
}
bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
// all sketch objects should be activated in the sketch selection modes by edit operation start
+ // in case of creation operation, there is an active widget, which activates own selection mode
if (theOperation->isEditOperation())
- activateObjectsInSketchMode(true);
+ aConnector->activateModuleSelectionModes();
}
void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
#ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
#endif
- // the objects activated in the sketch should be deactivated in order to do not have the specific
- // sketch selection mode activated on objects in neutral point of the application(no started operation)
- activateObjectsInSketchMode(false);
-
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
DataPtr aData = myCurrentSketch->data();
if (!aObjData->isValid())
aObj->setDisplayed(false);
}
- return;
}
+ else {
// Hide all sketcher sub-Objects
for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
FeaturePtr aFeature = myCurrentSketch->subFeature(i);
myCurrentSketch = CompositeFeaturePtr();
myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ // restore the module selection modes, which were changed on startSketch
+ aConnector->activateModuleSelectionModes();
}
void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
connectToPropertyPanel(false);
myIsPropertyPanelValueChanged = false;
myIsMouseOverViewProcessed = true;
-
- // the sketch objects selection should be activated in order to select any sketch
- // object
- activateObjectsInSketchMode(true);
}
void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
{
myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
-
- // after the plane is selected in the sketch, the sketch selection should be activated
- // it can not be performed in the sketch label widget because, we don't need to switch off
- // the selection by any label deactivation, but need to switch it off by stop the sketch
- activateObjectsInSketchMode(true);
}
void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
}
-void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive)
-{
- ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
- XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
-
- QIntList aModes;
- if (isActive)
- sketchSelectionModes(aModes);
- aDisplayer->activateObjects(aModes);
-}
-
void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
{
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
/// \param isToDisplay a flag about the display or erase the feature
void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay,
const bool isFlushRedisplay = true);
-
- /// Activates all visualized objects in the following selection modes: Dimension_Text/Line/Constraint,
- /// Shape Edge and Vertex. If the active flag is empty, it deactivates all modes
- /// \param isActive the flag whether the modes should be activated or deactivated
- void activateObjectsInSketchMode(const bool isActive);
-
private:
/// Gives a debug information about internal flags myIsMouseOverWindow and myIsPropertyPanelValueChanged
/// \return a string value
#include <XGUI_Selection.h>
#include <XGUI_ViewerProxy.h>
#include <XGUI_ActionsMgr.h>
+#include <XGUI_ModuleConnector.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_ViewerPrs.h>
#include <Config_PropManager.h>
#include <QLabel>
-//#include <QTimer>
#include <QApplication>
#include <QVBoxLayout>
#include <QCheckBox>
myLabel->setToolTip("");
myLabel->setIndent(5);
- //mySelectionTimer = new QTimer(this);
- //connect(mySelectionTimer, SIGNAL(timeout()), SLOT(setSketchingMode()));
- //mySelectionTimer->setSingleShot(true);
-
QVBoxLayout* aLayout = new QVBoxLayout(this);
ModuleBase_Tools::zeroMargins(aLayout);
aLayout->addWidget(myLabel);
//XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->closeLocalContexts();
emit planeSelected(plane());
- //setSketchingMode();
+ // after the plane is selected in the sketch, the sketch selection should be activated
+ // it can not be performed in the sketch label widget because, we don't need to switch off
+ // the selection by any label deactivation, but need to switch it off by stop the sketch
+ activateSelection(true);
// 8. Update sketcher actions
XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr();
void PartSet_WidgetSketchLabel::activateCustom()
{
std::shared_ptr<GeomAPI_Pln> aPlane = plane();
- if (aPlane.get())
+ if (aPlane.get()) {
+ activateSelection(true);
return;
+ }
bool aBodyIsVisualized = false;
XGUI_Displayer* aDisp = myWorkshop->displayer();
// We have to select a plane before any operation
showPreviewPlanes();
}
- QIntList aModes;
- aModes << TopAbs_FACE;
- aDisp->activateObjects(aModes);
+ activateSelection(true);
myLabel->setText(myText);
myLabel->setToolTip(myTooltip);
void PartSet_WidgetSketchLabel::deactivate()
{
- // Do not set selection mode if the widget was activated for a small moment
- //mySelectionTimer->stop();
- //XGUI_Displayer* aDisp = myWorkshop->displayer();
- //aDisp->closeLocalContexts();
erasePreviewPlanes();
+ activateSelection(false);
+
activateFilters(myWorkshop->module()->workshop(), false);
}
+void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
+{
+ if (toActivate) {
+ QIntList aModes;
+ std::shared_ptr<GeomAPI_Pln> aPlane = plane();
+ if (aPlane.get()) {
+ myWorkshop->moduleConnector()->module()->activeSelectionModes(aModes);
+ }
+ else {
+ aModes << TopAbs_FACE;
+ }
+ myWorkshop->moduleConnector()->activateSubShapesSelection(aModes);
+ } else {
+ myWorkshop->moduleConnector()->deactivateSubShapesSelection();
+ }
+}
+
void PartSet_WidgetSketchLabel::erasePreviewPlanes()
{
if (myPreviewDisplayed) {
return aDir;
}
-
-/*void PartSet_WidgetSketchLabel::setSketchingMode()
-{
- XGUI_Displayer* aDisp = myWorkshop->displayer();
- // Clear standard selection modes if they are defined
- //aDisp->activateObjects(aModes);
- //aDisp->openLocalContext();
-
- // Get default selection modes
-
- QIntList aModes;
- aModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
- aModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
- aModes.append(SketcherPrs_Tools::Sel_Constraint);
- aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
- aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
-
- aDisp->activateObjects(aModes);
-}*/
-
void PartSet_WidgetSketchLabel::showConstraints(bool theOn)
{
myShowConstraints->setChecked(theOn);
#include <TopoDS_Shape.hxx>
class QLabel;
-//class QTimer;
class XGUI_OperationMgr;
class XGUI_Workshop;
class QCheckBox;
/// The methiod called when widget is activated
virtual void activateCustom();
+ protected:
+ /// Activate or deactivate selection
+ void activateSelection(bool toActivate);
+
private slots:
/// Slot on change selection
void onSelectionChanged();
- /// Set sketch specific mode of selection
- //void setSketchingMode();
-
private:
/// Create preview of planes for sketch plane selection
/// \param theOrigin an origin of the plane
AISObjectPtr myXYPlane;
bool myPreviewDisplayed;
- //QTimer* mySelectionTimer;
-
QCheckBox* myShowConstraints;
};
const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
+#define DEBUG_CRASH_RESTORE_SELECTION
+
+//#define DEBUG_ACTIVATE_OBJECTS
+//#define DEBUG_DEACTIVATE
+//#define DEBUG_ACTIVATE_AIS
+//#define DEBUG_DEACTIVATE_AIS
+
//#define DEBUG_DISPLAY
-//#define DEBUG_ACTIVATE
//#define DEBUG_FEATURE_REDISPLAY
//#define DEBUG_SELECTION_FILTERS
-//#define DEBUG_USE_CLEAR_OUTDATED_SELECTION
// Workaround for bug #25637
void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
}
}
+QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", "))
+{
+ QStringList anInfo;
+ QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end();
+ for (; anIt != aLast; anIt++) {
+ anInfo.append(QString::number(*anIt));
+ }
+ return anInfo.join(theSeparator);
+}
XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
: myWorkshop(theWorkshop)
return myResult2AISObjectMap.contains(theObject);
}
-void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
+void XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
{
if (isVisible(theObject)) {
- redisplay(theObject, isUpdateViewer);
+ redisplay(theObject, theUpdateViewer);
} else {
AISObjectPtr anAIS;
}
}
if (anAIS)
- display(theObject, anAIS, isShading, isUpdateViewer);
+ display(theObject, anAIS, isShading, theUpdateViewer);
}
}
}
void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
- bool isShading, bool isUpdateViewer)
+ bool isShading, bool theUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed);
emit objectDisplayed(theObject, theAIS);
- activate(anAISIO, myActiveSelectionModes);
+ activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
}
- if (isUpdateViewer)
+ if (theUpdateViewer)
updateViewer();
}
-void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
+void XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer)
{
if (!isVisible(theObject))
return;
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
emit beforeObjectErase(theObject, anObject);
- aContext->Remove(anAIS, isUpdateViewer);
+ aContext->Remove(anAIS, theUpdateViewer);
}
}
myResult2AISObjectMap.remove(theObject);
}
-void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
+void XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
{
if (!isVisible(theObject))
return;
if (aPrs) {
AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
if (!aAIS_Obj) {
- erase(theObject, isUpdateViewer);
+ erase(theObject, theUpdateViewer);
return;
}
if (aAIS_Obj != aAISObj) {
#ifdef DEBUG_FEATURE_REDISPLAY
qDebug(" Redisplay happens");
#endif
- if (isUpdateViewer)
+ if (theUpdateViewer)
updateViewer();
}
}
}
-void XGUI_Displayer::deactivate(ObjectPtr theObject)
+void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer)
{
+#ifdef DEBUG_DEACTIVATE
+ QString anInfoStr = ModuleBase_Tools::objectInfo(theObject);
+ qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = ").
+ arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
+ arg(anInfoStr).
+ toStdString().c_str());
+#endif
if (isVisible(theObject)) {
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
AISObjectPtr anObj = myResult2AISObjectMap[theObject];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- aContext->Deactivate(anAIS);
-#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
+
+ deactivateAIS(anAIS);
+ // the selection from the previous activation modes should be cleared manually (#26172)
aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
- updateViewer();
-#endif
+ if (theUpdateViewer)
+ updateViewer();
}
}
}
}
-void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList)
+void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
+ const bool theUpdateViewer)
{
-#ifdef DEBUG_ACTIVATE
- qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3").
- arg(theModes.size()).
- arg(myActiveSelectionModes.size()).
+ // Convert shape types to selection types
+ QIntList aModes;
+ foreach(int aType, theModes) {
+ if (aType > TopAbs_SHAPE)
+ aModes.append(aType);
+ else
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
+ }
+
+#ifdef DEBUG_ACTIVATE_OBJECTS
+ QStringList anInfo;
+ QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end();
+ for (; anIt != aLast; ++anIt) {
+ anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
+ }
+ QString anInfoStr = anInfo.join(", ");
+
+ qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5").
+ arg(aModes.size()).arg(qIntListInfo(aModes)).
+ arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)).
+ arg(anInfoStr).
toStdString().c_str());
#endif
// In order to avoid doblications of selection modes
QIntList aNewModes;
- foreach (int aMode, theModes) {
+ foreach (int aMode, aModes) {
if (!aNewModes.contains(aMode))
aNewModes.append(aMode);
}
if (!aContext->HasOpenedContext())
return;
- // we need to block the sort of the viewer selector during deactivate/activate because
- // it takes a lot of time if there are a many objects are processed. It can be performed
- // manualy after the activation is peformed
- //Handle(StdSelect_ViewerSelector3d) aSelector = aContext->LocalContext()->MainSelector();
- //bool isUpdateSortPossible = !aSelector.IsNull() && aSelector->IsUpdateSortPossible();
- //if (!aSelector.IsNull())
- // aSelector->SetUpdateSortPossible(false);
-
//aContext->UseDisplayedObjects();
//myUseExternalObjects = true;
Handle(AIS_InteractiveObject) anAISIO;
AIS_ListOfInteractive aPrsList;
if (theObjList.isEmpty())
- ::displayedObjects(aContext, aPrsList);
+ return;
else {
foreach(ObjectPtr aObj, theObjList) {
if (myResult2AISObjectMap.contains(aObj))
AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
anAISIO = aLIt.Value();
- activate(anAISIO, myActiveSelectionModes);
- }
- // restore the sorting flag and perform the sort of selection
- //if (!aSelector.IsNull()) {
- // aSelector->SetUpdateSortPossible(isUpdateSortPossible);
- // aSelector->UpdateSort();
- //}
-}
-
-
-void XGUI_Displayer::deactivateObjects()
-{
- myActiveSelectionModes.clear();
- Handle(AIS_InteractiveContext) aContext = AISContext();
- // Open local context if there is no one
- if (!aContext->HasOpenedContext())
- return;
-
- //aContext->NotUseDisplayedObjects();
- AIS_ListOfInteractive aPrsList;
- ::displayedObjects(aContext, aPrsList);
-
- AIS_ListIteratorOfListOfInteractive aLIt;
- //Handle(AIS_Trihedron) aTrihedron;
- Handle(AIS_InteractiveObject) anAISIO;
- for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
- anAISIO = aLIt.Value();
- aContext->Deactivate(anAISIO);
-#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
- aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
- updateViewer();
-#endif
+ activate(anAISIO, myActiveSelectionModes, theUpdateViewer);
}
}
aContext->ActivatedModes(anAIS, aModes);
return aModes.Extent() > 0;
}
-
-void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer)
+void XGUI_Displayer::setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
if (aContext->HasOpenedContext()) {
aContext->UnhilightSelected();
aContext->ClearSelected();
- //if (aSelected.size() > 0) {
foreach (ModuleBase_ViewerPrs aPrs, theValues) {
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
+#ifdef DEBUG_CRASH_RESTORE_SELECTION
+#else
aContext->AddOrRemoveSelected(aShape, false);
+#endif
} else {
ObjectPtr anObject = aPrs.object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
}
}
}
- if (isUpdateViewer)
+ if (theUpdateViewer)
updateViewer();
}
}
}
-void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
+void XGUI_Displayer::eraseAll(const bool theUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if (!aContext.IsNull()) {
aContext->Remove(anIO, false);
}
}
- if (isUpdateViewer)
+ if (theUpdateViewer)
updateViewer();
}
myResult2AISObjectMap.clear();
}
+void XGUI_Displayer::deactivateTrihedron() const
+{
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+
+ AIS_ListOfInteractive aList;
+ aContext->DisplayedObjects(aList, true);
+ AIS_ListIteratorOfListOfInteractive aIt;
+ for (aIt.Initialize(aList); aIt.More(); aIt.Next()) {
+ Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value());
+ if (!aTrihedron.IsNull()) {
+ aContext->Deactivate(aTrihedron);
+ }
+ }
+}
+
void XGUI_Displayer::openLocalContext()
{
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
//aContext->ClearCurrents();
aContext->OpenLocalContext();
+ deactivateTrihedron();
//aContext->NotUseDisplayedObjects();
//myUseExternalObjects = false;
}
}
-void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
+void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) {
aContext->AddFilter(aFilter);
}
- if (isUpdateViewer)
+ if (theUpdateViewer)
updateViewer();
//myUseExternalObjects = false;
aContext->UpdateCurrentViewer();
}
+void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
+ const int theMode, const bool theUpdateViewer) const
+{
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ aContext->Activate(theIO, theMode, theUpdateViewer);
+
+#ifdef DEBUG_ACTIVATE_AIS
+ ObjectPtr anObject = getObject(theIO);
+ anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
+ qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
+#endif
+}
+
+void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const
+{
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ if (theMode == -1)
+ aContext->Deactivate(theIO);
+ else
+ aContext->Deactivate(theIO, theMode);
+
+#ifdef DEBUG_DEACTIVATE_AIS
+ ObjectPtr anObject = getObject(theIO);
+ anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
+ qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str());
+#endif
+}
+
Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
{
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
aContext->OpenLocalContext();
+ deactivateTrihedron();
}
return aContext;
}
return myAndFilter;
}
-void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
+void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
if (!anAISIO.IsNull()) {
- aContext->Display(anAISIO, isUpdate);
+ aContext->Display(anAISIO, theUpdateViewer);
if (aContext->HasOpenedContext()) {
- //if (myUseExternalObjects) {
- if (myActiveSelectionModes.size() == 0)
- aContext->Activate(anAISIO);
- else {
- foreach(int aMode, myActiveSelectionModes) {
- aContext->Activate(anAISIO, aMode);
- }
+ if (myActiveSelectionModes.size() == 0)
+ activateAIS(anAISIO, 0, theUpdateViewer);
+ else {
+ foreach(int aMode, myActiveSelectionModes) {
+ activateAIS(anAISIO, aMode, theUpdateViewer);
}
- //}
+ }
}
}
}
-void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
+void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
if (!anAISIO.IsNull()) {
- aContext->Remove(anAISIO, isUpdate);
+ aContext->Remove(anAISIO, theUpdateViewer);
}
}
-void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
+void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer)
{
if (theMode == NoMode)
return;
Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
aContext->SetDisplayMode(aAISIO, theMode, false);
// Redisplay in order to update new mode because it could be not computed before
- if (toUpdate)
+ if (theUpdateViewer)
updateViewer();
}
}
void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
- const QIntList& theModes) const
+ const QIntList& theModes,
+ const bool theUpdateViewer) const
{
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull() || theIO.IsNull())
aContext->ActivatedModes(theIO, aTColModes);
TColStd_ListIteratorOfListOfInteger itr( aTColModes );
QIntList aModesActivatedForIO;
- //bool isDeactivated = false;
+ bool isDeactivated = false;
for (; itr.More(); itr.Next() ) {
Standard_Integer aMode = itr.Value();
if (!theModes.contains(aMode)) {
-#ifdef DEBUG_ACTIVATE
- qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
-#endif
- aContext->Deactivate(theIO, aMode);
- //isDeactivated = true;
+ deactivateAIS(theIO, aMode);
+ isDeactivated = true;
}
else {
aModesActivatedForIO.append(aMode);
-#ifdef DEBUG_ACTIVATE
- qDebug(QString(" active: %1").arg(aMode).toStdString().c_str());
-#endif
}
}
-#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
if (isDeactivated) {
+ // the selection from the previous activation modes should be cleared manually (#26172)
aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
- updateViewer();
+ if (theUpdateViewer)
+ updateViewer();
}
-#endif
+
// loading the interactive object allowing the decomposition
- if (aTColModes.IsEmpty())
+ if (aTColModes.IsEmpty()) {
aContext->Load(theIO, -1, true);
+ }
// trihedron AIS check should be after the AIS loading.
// If it is not loaded, it is steel selectable in the viewer.
// In order to clear active modes list
if (theModes.size() == 0) {
//aContext->Load(anAISIO, 0, true);
- aContext->Activate(theIO);
- #ifdef DEBUG_ACTIVATE
- qDebug("activate in all modes");
- #endif
+ activateAIS(theIO, 0, theUpdateViewer);
} else {
foreach(int aMode, theModes) {
//aContext->Load(anAISIO, aMode, true);
if (!aModesActivatedForIO.contains(aMode)) {
- aContext->Activate(theIO, aMode);
- #ifdef DEBUG_ACTIVATE
- qDebug(QString("activate: %1").arg(aMode).toStdString().c_str());
- #endif
+ activateAIS(theIO, aMode, theUpdateViewer);
}
}
}
}
-QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate)
+QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer)
{
if (!isVisible(theObject))
return Qt::black;
int aR, aG, aB;
anAISObj->getColor(aR, aG, aB);
anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue());
- if (toUpdate)
+ if (theUpdateViewer)
updateViewer();
return QColor(aR, aG, aB);
}
/// Display the feature. Obtain the visualized object from the feature.
/// \param theObject an object to display
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
/// Returns true if the Feature succesfully displayed
- void display(ObjectPtr theObject, bool isUpdateViewer = true);
+ void display(ObjectPtr theObject, bool theUpdateViewer = true);
/// Display the given AIS object. To hide this object use corresponde erase method
/// \param theAIS AIOS object to display
- /// \param isUpdate the parameter whether the viewer should be update immediatelly
- void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void displayAIS(AISObjectPtr theAIS, bool theUpdateViewer = true);
/** Redisplay the shape if it was displayed
* \param theObject an object instance
- * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
*/
- void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
+ void redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
/**
* Add presentations to current selection. It unhighlight and deselect the current selection.
* The shape and result components are processed in the values. If the presentation shape is not
* empty, select it, otherwise select the result.
* \param theValues a list of presentation to be selected
- * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
*/
- void setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer = true);
+ void setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
/// Unselect all objects
/// Erase the feature and a shape.
/// \param theObject an object instance
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void erase(ObjectPtr theObject, const bool theUpdateViewer = true);
/// Erase the given AIS object displayed by corresponded display method
/// \param theAIS instance of AIS object
- /// \param isUpdate the parameter whether the viewer should be update immediatelly
- void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
/// Erase all presentations
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void eraseAll(const bool isUpdateViewer = true);
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void eraseAll(const bool theUpdateViewer = true);
/// Deactivates selection of sub-shapes
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void closeLocalContexts(const bool isUpdateViewer = true);
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void closeLocalContexts(const bool theUpdateViewer = true);
/// \brief Add selection filter
/// \param theFilter a filter instance
/// Updates the viewer
void updateViewer() const;
+ /// Activate interactive context
+ /// \param theIO
+ /// \param theMode
+ void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
+ const bool theUpdateViewer) const;
+
+ /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
+ void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
+
/// Searches the interactive object by feature
/// \param theObject the object or presentable feature
/// \return theIO an interactive object
/// Deactivates the given object (not allow selection)
/// \param theObject object to deactivate
- void deactivate(ObjectPtr theObject);
+ void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
/// Activates the given object (it can be selected)
/// \param theObject object to activate
/// Activates in local context displayed outside of the context.
/// \param theModes - modes on which it has to be activated (can be empty)
- /// \param theObjList - list of objects which has to be activated. Can be empty. In this case all displayed objects will be used.
- void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList = QObjectPtrList());
-
- /// Activates in local context displayed outside of the context.
- void deactivateObjects();
+ /// \param theObjList - list of objects which has to be activated.
+ void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
+ const bool theUpdateViewer = true);
/// Sets display mode for the given object if this object is displayed
- void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
+ void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
/// Returns current display mode for the given object.
/// If object is not dis played then returns NoMode.
/// Set color on presentation of an object if it is displayed
/// \param theObject an object
/// \param theColor a color which has to be set
- /// \param toUpdate update viewer flag
+ /// \param theUpdateViewer update viewer flag
/// \return previously defined color on the object
- QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true);
+ QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
signals:
/// Signal on object display
/// \param theObject an object instance
/// \param theAIS AIS presentation
/// \param isShading flag to show in shading mode
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
/// \return true if the object is succesfully displayed
void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
- bool isUpdateViewer = true);
+ bool theUpdateViewer = true);
private:
/// Activates the interactive object in the local context.
/// \param theIO an interactive object
/// \param theModes - modes on which it has to be activated (can be empty)
- void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
+ void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
+ const bool theUpdateViewer) const;
+
+ /// Find a trihedron in a list of displayed presentations and deactivate it.
+ void deactivateTrihedron() const;
/// Opens local context. Does nothing if it is already opened.
void openLocalContext();
connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
-
- //myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
}
XGUI_ModuleConnector::~XGUI_ModuleConnector()
{
- //myDocumentShapeFilter.Nullify();
}
ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
{
XGUI_Displayer* aDisp = myWorkshop->displayer();
- // Close context if it was opened in order to clear stsndard selection modes
- //aDisp->closeLocalContexts(false);
- //aDisp->openLocalContext();
- // Convert shape types to selection types
- QIntList aModes;
- foreach(int aType, theTypes) {
- if (aType > TopAbs_SHAPE)
- aModes.append(aType);
- else
- aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
- }
- aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects()));
- //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
- //aDisp->addSelectionFilter(myDocumentShapeFilter);
+ aDisp->activateObjects(theTypes, activeObjects(aDisp->displayedObjects()));
}
void XGUI_ModuleConnector::deactivateSubShapesSelection()
{
- XGUI_Displayer* aDisp = myWorkshop->displayer();
// Clear selection modes
+ activateModuleSelectionModes();
+}
+
+void XGUI_ModuleConnector::activateModuleSelectionModes()
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
QIntList aModes;
- // TODO: check on OCC6.9.0
- // the module current active modes should not be deactivated in order to save the objects selected
- // the deactivate object in the mode of selection leads to the object is deselected in the viewer.
- // But, in OCC6.8.0 this deselection does not happened automatically. It is necessary to call
- // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in
- // the OCC6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside
- // Deactivate method of AIS_InteractiveContext. In this case, we need not call it.
module()->activeSelectionModes(aModes);
aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects()));
- // The document limitation selection has to be only during operation
- //aDisp->removeSelectionFilter(myDocumentShapeFilter);
- //aDisp->closeLocalContexts(false);
}
AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
#include "XGUI.h"
#include <ModuleBase_Definitions.h>
#include <ModuleBase_IWorkshop.h>
-#include <ModuleBase_ViewerFilters.h>
class Handle_AIS_InteractiveContext;
class XGUI_Workshop;
/// Types has to be dined according to TopAbs_ShapeEnum
virtual void activateSubShapesSelection(const QIntList& theTypes);
+ /// Activate objects in the module selection modes(opens local context)
+ virtual void activateModuleSelectionModes();
+
/// Deactivate sub-shapes selection (closes local context)
virtual void deactivateSubShapesSelection();
/// Reference to workshop
XGUI_Workshop* myWorkshop;
-
- /// A filter which provides selection within a current document or whole PartSet
- Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter;
};
#endif
// of redisplay is called. This modification is made in order to have the line is updated
// by creation of a horizontal constraint on the line by preselection
myDisplayer->redisplay(aObj, false);
- //if (myOperationMgr->hasOperation()) {
- // ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
- // if (!aOperation->isEditOperation() &&
- // aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
- if (!myModule->canActivateSelection(aObj)) {
- if (myDisplayer->isActive(aObj))
- myDisplayer->deactivate(aObj);
- }
+ // Deactivate object of current operation from selection
+ deactivateActiveObject(aObj, false);
} else { // display object if the current operation has it
if (displayObject(aObj)) {
- //ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
- //if (aOperation && aOperation->hasObject(aObj)) {
- if (!myModule->canActivateSelection(aObj)) {
- #ifdef DEBUG_FEATURE_REDISPLAY
- QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
- qDebug(QString(" display object = %1").arg(anObjInfo).toStdString().c_str());
- #endif
- // Deactivate object of current operation from selection
- if (myDisplayer->isActive(aObj))
- myDisplayer->deactivate(aObj);
- }
+ // Deactivate object of current operation from selection
+ deactivateActiveObject(aObj, false);
}
}
}
myDisplayer->updateViewer();
}
+//******************************************************
+void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
+{
+ if (!myModule->canActivateSelection(theObject)) {
+ if (myDisplayer->isActive(theObject))
+ myDisplayer->deactivate(theObject, theUpdateViewer);
+ }
+}
+
//******************************************************
void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
{
updateCommandStatus();
myModule->operationStarted(theOperation);
+
+ // the objects of the current operation should be deactivated
+ QObjectPtrList anObjects;
+ FeaturePtr aFeature = theOperation->feature();
+ anObjects.append(aFeature);
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+ anObjects.append(*aIt);
+ }
+ QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+ for (; anIt != aLast; anIt++)
+ deactivateActiveObject(*anIt, false);
+ if (anObjects.size() > 0)
+ myDisplayer->updateViewer();
}
//******************************************************
hidePropertyPanel();
myPropertyPanel->cleanContent();
- // Activate objects created by current operation
- // in order to clean selection modes
- // the deactivation should be pefromed in the same place, where the mode is activated,
- // e.g. activation in the current widget activation, deactivation - in the widget's deactivation
- //QIntList aModes;
- //myDisplayer->activateObjects(aModes);
myModule->operationStopped(theOperation);
- // if the operation is nested, do not deactivate objects
- //if (myOperationMgr->operationsCount() == 0) {
- // Activate selection mode for all objects
+ // the deactivated objects of the current operation should be activated back.
+ // They were deactivated on operation start or an object redisplay
+ QObjectPtrList anObjects;
+ FeaturePtr aFeature = theOperation->feature();
+ if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
+ anObjects.append(aFeature);
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+ ResultPtr anObject = *aIt;
+ if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
+ anObjects.append(anObject);
+ }
+ }
QIntList aModes;
- // TODO: check on OCC_6.9.0
- // the module current active modes should not be deactivated in order to save the objects selected
- // the deactivate object in the mode of selection leads to the object is deselected in the viewer.
- // But, in OCC_6.8.0 this deselection does not happened automatically. It is necessary to call
- // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in
- // the OCC_6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside
- // Deactivate method of AIS_InteractiveContext. In this case, we need not call it.
module()->activeSelectionModes(aModes);
- myDisplayer->activateObjects(aModes);
- //}
+ myDisplayer->activateObjects(aModes, anObjects);
}
/// Process feature update message
void onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
- ///Process feature created message
+ /// Process feature created message
void onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
/// Process feature redisplay message
void onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& );
+ /// Deactivates the object, if it is active and the module returns that the activation
+ /// of selection for the object is not possible currently(the current operation uses it)
+ /// \param theObject an object
+ /// \param theUpdateViewer a boolean flag to update viewer immediately
+ void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer);
+
/// Display all results
//void displayAllResults();