+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
// File: XGUI_Displayer.cpp
// Created: 20 Apr 2014
// Author: Natalia ERMOLAEVA
#include "XGUI_Displayer.h"
-#include "XGUI_Viewer.h"
#include "XGUI_Workshop.h"
#include "XGUI_ViewerProxy.h"
+#include <AppElements_Viewer.h>
+
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_ICustomPrs.h>
#include <AIS_InteractiveContext.hxx>
#include <AIS_LocalContext.hxx>
#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)
{
}
GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
bool isShading = false;
- if (aPrs) {
+ if (aPrs.get() != NULL) {
anAIS = aPrs->getAISObject(AISObjectPtr());
} else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (aResult) {
+ if (aResult.get() != NULL) {
std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
- if (aShapePtr) {
+ if (aShapePtr.get() != NULL) {
anAIS = AISObjectPtr(new GeomAPI_AISObject());
anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
//anAIS->createShape(aShapePtr);
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, isUpdateViewer);
- if (aContext->HasOpenedContext()) {
- if (myUseExternalObjects) {
- if (myActiveSelectionModes.size() == 0)
- aContext->Activate(anAISIO);
- else {
- foreach(int aMode, myActiveSelectionModes) {
- aContext->Activate(anAISIO, aMode);
- }
- }
- }
+ 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);
}
+ 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::erase(ObjectPtr theObject, const bool isUpdateViewer)
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()
{
aContext->ClearCurrents();
aContext->OpenLocalContext();
- aContext->NotUseDisplayedObjects();
+ //aContext->NotUseDisplayedObjects();
- myUseExternalObjects = false;
+ //myUseExternalObjects = false;
myActiveSelectionModes.clear();
SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
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) {
+ //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);
-
- Handle(AIS_Trihedron) aTrihedron;
- AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
- for(; aLIt.More(); aLIt.Next()){
- aTrihedron = Handle(AIS_Trihedron)::DownCast(aLIt.Value());
- if (!aTrihedron.IsNull()) {
- aContext->Deactivate(aTrihedron);
- break;
- }
- }
-
- //Activate all displayed objects with the module modes
- //AIS_ListOfInteractive aPrsList;
- //aContext->DisplayedObjects(aPrsList, true);
-
- //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())
- continue;
-
- 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)
{