#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_AttributeIntArray.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
#include <ModuleBase_BRepOwner.h>
#include <ModuleBase_IModule.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_IPresentable.h>
#include <GeomAPI_ICustomPrs.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_IScreenParams.h>
#include <SUIT_ResourceMgr.h>
GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
bool isShading = false;
if (aPrs.get() != NULL) {
+ GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast<GeomAPI_IScreenParams>(theObject);
+ if (aScreen.get()) {
+ aScreen->setScreenPlane(getScreenPlane());
+ aScreen->setViewScale(getViewScale());
+ }
anAIS = aPrs->getAISObject(anAIS);
- if (anAIS.get()) {
+ //if (anAIS.get()) {
// correct deviation coefficient for
/*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
if (!anAISPrs.IsNull()) {
//ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
}
}*/
- }
+ //}
} else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get() != NULL) {
if (aContext.IsNull())
return aErased;
- AISObjectPtr anObject = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObject = myResult2AISObjectMap.value(theObject);
if (anObject) {
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
if (aPrs) {
+ GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast<GeomAPI_IScreenParams>(theObject);
+ if (aScreen.get()) {
+ aScreen->setScreenPlane(getScreenPlane());
+ aScreen->setViewScale(getViewScale());
+ }
AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
if (!aAIS_Obj) {
aRedisplayed = erase(theObject, theUpdateViewer);
// compsolid is not visualized in the viewer,
// but should have presentation when all sub solids are
// visible. It is useful for highlight presentation where compsolid shape is selectable
- if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
- ResultCompSolidPtr aCompsolidResult =
- std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+ if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) {
+ ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
ObjectPtr anObject = aPrs->object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
if (aResult.get() && isVisible(aResult)) {
- AISObjectPtr anObj = myResult2AISObjectMap[aResult];
+ AISObjectPtr anObj = myResult2AISObjectMap.value(aResult);
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
// The methods are replaced in order to provide multi-selection, e.g. restore selection
bool aErased = false;
Handle(AIS_InteractiveContext) aContext = AISContext();
if (!aContext.IsNull()) {
- foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
+#ifdef OPTIMIZE_PRS
+ foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) {
+ AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
+#else
+ foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) {
AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+#endif
// erase an object
Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
if (!anIO.IsNull()) {
//**************************************************************
AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
{
+#ifdef OPTIMIZE_PRS
+ return myResult2AISObjectMap.value(theObject);
+#else
AISObjectPtr anIO;
if (myResult2AISObjectMap.contains(theObject))
anIO = myResult2AISObjectMap[theObject];
return anIO;
+#endif
}
//**************************************************************
//**************************************************************
ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
{
+#ifdef OPTIMIZE_PRS
+ ObjectPtr anObject = myResult2AISObjectMap.value(theIO);
+#else
ObjectPtr anObject;
- foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) {
- AISObjectPtr aAIS = myResult2AISObjectMap[anObj];
+ ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin();
+ for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) {
+ const AISObjectPtr& aAIS = aMapIter.value();
Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
if (anAIS == theIO)
- anObject = anObj;
+ anObject = aMapIter.key();
if (anObject.get())
break;
}
+#endif
if (!anObject.get()) {
std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
if (!theIO.IsNull()) {
//**************************************************************
void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
{
+#ifdef OPTIMIZE_PRS
+ QObjectPtrList aDispList = myResult2AISObjectMap.objects();
+#else
QObjectPtrList aDispList = myResult2AISObjectMap.keys();
+#endif
foreach(ObjectPtr aObj, aDispList) {
if (!theList.contains(aObj))
erase(aObj, false);
//**************************************************************
void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
{
+#ifdef OPTIMIZE_PRS
+ myResult2AISObjectMap.add(theObject, theAIS);
+#else
myResult2AISObjectMap[theObject] = theAIS;
+#endif
#ifdef DEBUG_DISPLAY
std::ostringstream aPtrStr;
std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
{
QStringList aContent;
- foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
+#ifdef OPTIMIZE_PRS
+ foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) {
+ AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
+#else
+ foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) {
AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+#endif
std::ostringstream aPtrStr;
aPtrStr << "aObj = " << aObj.get() << ":";
aPtrStr << "anAIS = " << aAISObj.get() << ":";
if (aAISObj.get() == NULL) {
// if result is a result of a composite feature, it is visualized by visualization of
// composite children, so we should get one of this presentations
- ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+ ResultBodyPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
aAISObj = getAISObject(aCompSolid->subResult(0));
}
/// If count of calls setSelectec is even, the object stays in the previous state
/// (selected, deselected)
/// OCCT: to write about the problem that active owners method returns one owner several times
- QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
+ QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
for (; anOwnersIt.More(); anOwnersIt.Next()) {
anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
- if (aSelectedIds.contains((long)anOwner.get()))
+ if (aSelectedIds.contains((size_t)anOwner.get()))
continue;
- aSelectedIds.append((long)anOwner.get());
+ aSelectedIds.append((size_t)anOwner.get());
Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
if (!BROwnr.IsNull() && BROwnr->HasShape()) {
{
return myWorkshop->selectionActivate();
}
+
+//**************************************************************
+GeomPlanePtr XGUI_Displayer::getScreenPlane() const
+{
+ GeomPlanePtr aResult;
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
+ Handle(V3d_View) aView;
+ for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) {
+ aView = aViewer->ActiveView();
+ break;
+ }
+ if (!aView.IsNull()) {
+ double aEyeX, aEyeY, aEyeZ;
+ aView->Eye(aEyeX, aEyeY, aEyeZ);
+
+ double aProjX, aProjY, aProjZ;
+ aView->Proj(aProjX, aProjY, aProjZ);
+
+ GeomPointPtr aPnt = GeomPointPtr(new GeomAPI_Pnt(aEyeX, aEyeY, aEyeZ));
+ GeomDirPtr aDir = GeomDirPtr(new GeomAPI_Dir(aProjX, aProjY, aProjZ));
+
+ aResult = GeomPlanePtr(new GeomAPI_Pln(aPnt, aDir));
+ }
+ }
+ return aResult;
+}
+
+double XGUI_Displayer::getViewScale() const
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (!aContext.IsNull()) {
+ Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
+ Handle(V3d_View) aView;
+ for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) {
+ aView = aViewer->ActiveView();
+ break;
+ }
+ return aView->Camera()->Scale();
+ }
+ return 1;
+}