#include <SelectMgr_ListOfFilter.hxx>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <TColStd_MapOfTransient.hxx>
+#include <TColStd_MapIteratorOfMapOfTransient.hxx>
+
#include <set>
const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity
XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
- : myUseExternalObjects(false), myWorkshop(theWorkshop)
+ : myWorkshop(theWorkshop)
{
}
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
if (!anAISIO.IsNull()) {
myResult2AISObjectMap[theObject] = theAIS;
+
+ closeLocalContexts(false);
aContext->Display(anAISIO, false);
aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
-
+ // Customization of presentation
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
if (aFeature.get() != NULL) {
GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
if (aCustPrs.get() != NULL)
aCustPrs->customisePresentation(theAIS);
}
- if (aContext->HasOpenedContext()) {
- if (myUseExternalObjects) {
- if (myActiveSelectionModes.size() == 0)
- aContext->Activate(anAISIO);
- else {
- foreach(int aMode, myActiveSelectionModes) {
- aContext->Activate(anAISIO, aMode);
- }
- }
- }
- }
+ openLocalContext();
+ aContext->Load(anAISIO, -1, true);
+ activate(theObject);
+ //if (aContext->HasOpenedContext()) {
+ //if (myUseExternalObjects) {
+ //if (myActiveSelectionModes.size() == 0)
+ // aContext->Activate(anAISIO);
+ //else {
+ // foreach(int aMode, myActiveSelectionModes) {
+ // aContext->Activate(anAISIO, aMode);
+ // }
+ //}
+ //}
+ //}
}
if (isUpdateViewer)
updateViewer();
void XGUI_Displayer::activate(ObjectPtr theFeature)
{
- QIntList aModes;
- activate(theFeature, aModes);
+ activate(theFeature, myActiveSelectionModes);
}
void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
AISObjectPtr anObj = myResult2AISObjectMap[theObject];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- if (aContext->HasOpenedContext()) {
- aContext->Load(anAIS, -1, true);
- }
aContext->Deactivate(anAIS);
+ //if (aContext->HasOpenedContext()) {
+ // aContext->Load(anAIS, -1, true);
+ //}
+ // In order to clear active modes list
if (theModes.size() > 0) {
foreach(int aMode, theModes) {
aContext->Activate(anAIS, aMode);
}
}
+void XGUI_Displayer::activateObjects(const QIntList& theModes)
+{
+ // In order to avoid doblications of selection modes
+ myActiveSelectionModes.clear();
+ foreach (int aMode, theModes) {
+ if (!myActiveSelectionModes.contains(aMode))
+ myActiveSelectionModes.append(aMode);
+ }
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ // Open local context if there is no one
+ if (!aContext->HasOpenedContext())
+ return;
+
+ //aContext->UseDisplayedObjects();
+ //myUseExternalObjects = true;
+
+ AIS_ListOfInteractive aPrsList;
+ aContext->DisplayedObjects(aPrsList, true);
+ //Deactivate trihedron which can be activated in local selector
+
+ Handle(AIS_Trihedron) aTrihedron;
+ AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
+ Handle(AIS_InteractiveObject) anAISIO;
+ for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
+ anAISIO = aLIt.Value();
+ aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
+ if (!aTrihedron.IsNull()) {
+ aContext->Deactivate(aTrihedron);
+ } else {
+ //aContext->Load(anAISIO, -1, true);
+ // In order to clear active modes list
+ aContext->Deactivate(anAISIO);
+ if (myActiveSelectionModes.size() == 0)
+ aContext->Activate(anAISIO);
+ else {
+ foreach(int aMode, myActiveSelectionModes) {
+ aContext->Activate(anAISIO, aMode);
+ }
+ }
+ }
+ }
+}
+
+
+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;
+ aContext->DisplayedObjects(aPrsList);
+
+ AIS_ListIteratorOfListOfInteractive aLIt;
+ Handle(AIS_Trihedron) aTrihedron;
+ Handle(AIS_InteractiveObject) anAISIO;
+ for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
+ anAISIO = aLIt.Value();
+ aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
+ if (!aTrihedron.IsNull()) {
+ aContext->Deactivate(aTrihedron);
+ } else {
+ //aContext->Load(anAISIO, -1, true);
+ aContext->Deactivate(anAISIO);
+ //aContext->Activate(anAISIO);
+ }
+ }
+}
+
bool XGUI_Displayer::isActive(ObjectPtr theObject) const
{
Handle(AIS_InteractiveContext) aContext = AISContext();
updateViewer();
}
-void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
-{
- Handle(AIS_InteractiveContext) aContext = AISContext();
- if (aContext.IsNull())
- return;
-
- QObjectPtrList aRemoved;
- foreach (ObjectPtr aFeature, myResult2AISObjectMap.keys()) {
- if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
- AISObjectPtr anObj = myResult2AISObjectMap[aFeature];
- if (!anObj)
- continue;
- Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- if (!anAIS.IsNull()) {
- aContext->Remove(anAIS, false);
- aRemoved.append(aFeature);
- }
- }
- }
- foreach(ObjectPtr aObj, aRemoved) {
- myResult2AISObjectMap.remove(aObj);
- }
-
- if (isUpdateViewer)
- updateViewer();
-}
+//void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
+//{
+// Handle(AIS_InteractiveContext) aContext = AISContext();
+// if (aContext.IsNull())
+// return;
+//
+// QObjectPtrList aRemoved;
+// foreach (ObjectPtr aFeature, myResult2AISObjectMap.keys()) {
+// if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
+// AISObjectPtr anObj = myResult2AISObjectMap[aFeature];
+// if (!anObj)
+// continue;
+// Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
+// if (!anAIS.IsNull()) {
+// aContext->Remove(anAIS, false);
+// aRemoved.append(aFeature);
+// }
+// }
+// }
+// foreach(ObjectPtr aObj, aRemoved) {
+// myResult2AISObjectMap.remove(aObj);
+// }
+//
+// if (isUpdateViewer)
+// updateViewer();
+//}
void XGUI_Displayer::openLocalContext()
{
// in the closeLocalContex, which restore the global context filters
aContext->RemoveFilters();
- //aContext->ClearCurrents();
+ aContext->ClearCurrents();
aContext->OpenLocalContext();
+ //aContext->NotUseDisplayedObjects();
- qDebug("### Open Local context");
-
- aContext->NotUseDisplayedObjects();
-
- myUseExternalObjects = false;
+ //myUseExternalObjects = false;
myActiveSelectionModes.clear();
SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
SelectMgr_ListOfFilter aFilters;
aFilters.Assign(aContext->Filters());
- //aContext->ClearSelected();
+ aContext->ClearSelected();
aContext->CloseAllContexts(false);
- qDebug("### Close Local context");
-
// Redisplay all object if they were displayed in localContext
Handle(AIS_InteractiveObject) aAISIO;
foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
if (isUpdateViewer)
updateViewer();
- myUseExternalObjects = false;
+ //myUseExternalObjects = false;
myActiveSelectionModes.clear();
// Restore selection
Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
{
- return myWorkshop->viewer()->AISContext();
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
+ aContext->OpenLocalContext();
+ }
+ return aContext;
}
Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
if (!anAISIO.IsNull()) {
aContext->Display(anAISIO, isUpdate);
if (aContext->HasOpenedContext()) {
- if (myUseExternalObjects) {
- aContext->Deactivate(anAISIO);
+ //if (myUseExternalObjects) {
if (myActiveSelectionModes.size() == 0)
aContext->Activate(anAISIO);
else {
aContext->Activate(anAISIO, aMode);
}
}
- }
+ //}
}
}
}
}
}
-void XGUI_Displayer::activateObjects(const QIntList& theModes)
-{
- Handle(AIS_InteractiveContext) aContext = AISContext();
- // Open local context if there is no one
- if (!aContext->HasOpenedContext())
- return;
-
- aContext->UseDisplayedObjects();
- myUseExternalObjects = true;
- myActiveSelectionModes = theModes;
-
- //Deactivate trihedron which can be activated in local selector
- AIS_ListOfInteractive aPrsList;
- aContext->DisplayedObjects(aPrsList, true);
-
- AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
- Handle(AIS_InteractiveObject) anAISIO;
- Handle(AIS_Trihedron) aTrihedron;
- for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
- anAISIO = aLIt.Value();
- aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
- aContext->Deactivate(anAISIO);
- if (aTrihedron.IsNull()) {
- aContext->Load(anAISIO, -1, true);
- if (theModes.size() == 0)
- aContext->Activate(anAISIO);
- else {
- foreach(int aMode, theModes) {
- aContext->Activate(anAISIO, aMode);
- }
- }
- }
- }
-}
-
-
-void XGUI_Displayer::deactivateObjects()
-{
- Handle(AIS_InteractiveContext) aContext = AISContext();
- // Open local context if there is no one
- if (!aContext->HasOpenedContext())
- return;
-
- aContext->NotUseDisplayedObjects();
-}
-
void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
{