1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "HEXABLOCKGUI_OccGraphicView.hxx"
23 #include "HEXABLOCKGUI.hxx"
24 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
26 #include <SOCC_ViewModel.h>
27 #include <SUIT_ViewManager.h>
31 using namespace HEXABLOCK::GUI;
33 // -----------------------------------------------------------------------
34 // OccGraphicView implementation
35 // -----------------------------------------------------------------------
37 OccGraphicView::OccGraphicView( OCCViewer_ViewWindow* view, QWidget* parent ):
40 selectionMode(TopAbs_SHAPE)
42 TopoDS_Shape shapeToPreview;
43 previewShape = new AIS_Shape(shapeToPreview);
44 // previewShape->SetColor(Quantity_NOC_RED);
45 getContext()->SetColor( previewShape, Quantity_NOC_RED );
48 void OccGraphicView::setSelectionMode(TopAbs_ShapeEnum mode)
50 if (viewWindow == NULL || selectionMode == mode)
53 HEXABLOCKGUI::selectionMgr()->clearSelected();
59 void OccGraphicView::setSelectionMode(const QModelIndex& eltIndex)
62 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
63 if ( !treeVariant.isValid() ) return;
64 int eltType = treeVariant.toInt();
67 case VERTEX_TREE : setSelectionMode(TopAbs_VERTEX); break;
68 case VERTEX_DIR_TREE : setSelectionMode(TopAbs_VERTEX); break;
69 case EDGE_TREE : setSelectionMode(TopAbs_EDGE); break;
70 case EDGE_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
71 case QUAD_TREE : setSelectionMode(TopAbs_FACE); break;
72 case QUAD_DIR_TREE : setSelectionMode(TopAbs_FACE); break;
73 case HEXA_TREE : setSelectionMode(TopAbs_SHAPE); break;
74 case HEXA_DIR_TREE : setSelectionMode(TopAbs_SHAPE); break;
75 case GEOMSHAPE_TREE: setSelectionMode(TopAbs_SHAPE); break;
76 case GEOMSHAPE_DIR_TREE: setSelectionMode(TopAbs_SHAPE); break;
77 case GEOMPOINT_TREE: setSelectionMode(TopAbs_VERTEX); break;
78 case GEOMPOINT_DIR_TREE: setSelectionMode(TopAbs_VERTEX); break;
79 case GEOMEDGE_TREE: setSelectionMode(TopAbs_EDGE); break;
80 case GEOMEDGE_DIR_TREE: setSelectionMode(TopAbs_EDGE); break;
81 case GEOMFACE_TREE: setSelectionMode(TopAbs_FACE); break;
82 case GEOMFACE_DIR_TREE: setSelectionMode(TopAbs_FACE); break;
83 case PROPAGATION_TREE : setSelectionMode(TopAbs_EDGE); break;
84 case PROPAGATION_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
88 void OccGraphicView::getSelected(SALOME_ListIO& selectedObjects)
90 HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects/*, OCCViewer_Viewer::Type()*/ );
92 // SALOME_View* vf = dynamic_cast<SALOME_View*>(HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager()->getViewModel());
93 // if ( vf == NULL ) return;
94 // SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
95 // if (viewer == NULL)
97 // AIS_ListOfInteractive theList;
98 // viewer->getSelectedObjects (theList);
99 // AIS_ListIteratorOfListOfInteractive it (theList);
100 // //iterate on list:
101 // while (it.More ())
103 // Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast(it.Value()->GetOwner());
104 // if (!anIO.IsNull())
105 // salomeSelected.Append(anIO);
110 void OccGraphicView::clearSelection()
112 if (HEXABLOCKGUI::selectionMgr() == NULL)
115 HEXABLOCKGUI::selectionMgr()->clearSelected();
117 localSelection(TopAbs_SHAPE);
118 selectionMode = TopAbs_SHAPE;
121 void OccGraphicView::localSelection(const int theMode )
123 if (viewWindow == NULL || prs == NULL)
126 // remove all filters from selection
127 LightApp_SelectionMgr* sm = HEXABLOCKGUI::selectionMgr();
130 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
134 vf->LocalSelection( prs, theMode );
137 void OccGraphicView::globalSelection(const bool update )
139 if (viewWindow == NULL)
142 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
143 if ( vf == NULL ) return;
145 // Close local context
146 vf->GlobalSelection( update );
148 // Set selection filters in accordance with current mode
149 LightApp_SelectionMgr* sm = HEXABLOCKGUI::selectionMgr();
155 // Remove filters from AIS_InteractiveContext
156 Handle(AIS_InteractiveContext) ic;
157 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
160 ic = viewer->getAISContext();
166 void OccGraphicView::highlight( const QModelIndex & index, bool only )
169 // getting association(s) from model
170 QMultiMap< QString, int > assocEntrySubIDs;
172 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
173 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
174 if (docModel == NULL) return;
176 assocEntrySubIDs += docModel->getAssocShapesIds(index);
177 highlight( assocEntrySubIDs, only );
181 void OccGraphicView::highlight( const QModelIndexList & indexList, bool only )
184 QMultiMap< QString, int > assocEntrySubIDs;
186 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
187 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
188 PatternDataModel* pModel = HEXABLOCKGUI::currentDocGView->getPatternDataModel();
189 if (docModel == NULL || pModel == NULL) return;
191 foreach( const QModelIndex& anEltIndex, indexList)
193 assocEntrySubIDs += docModel->getAssocShapesIds(anEltIndex);
195 highlight( assocEntrySubIDs, only );
198 void OccGraphicView::highlightSubShapes(const Handle(AIS_Shape)& anObj,
199 const TColStd_IndexedMapOfInteger& aIndexMap, bool only)
201 if (viewWindow == NULL || anObj.IsNull() )
205 Handle (AIS_InteractiveContext) anIC = getContext();
206 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
210 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
211 anIC->SetAutomaticHilight( false );
213 if (only) // * clear current highlighted if asked
214 anIC->ClearSelected( false );
216 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
218 // Get entity owners for all activated selection modes
219 getEntityOwners( anObj, anIC, anAllMap );
221 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
222 indicesToOwners( aIndexMap, anObj->Shape(), anAllMap, aToHiliteMap );
224 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
225 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
227 anIC->SetAutomaticHilight( isAutoHilight );
228 anIC->HilightSelected( false );
231 void OccGraphicView::highlight( const QMultiMap<QString, int>& entrySubIDs, bool only)
234 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL)
237 SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>( viewWindow->getViewManager()->getViewModel() );
238 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
239 if (soccViewer == NULL || docModel == NULL)
242 foreach ( QString shapeName, entrySubIDs.uniqueKeys() )
244 QString shapeEntry = docModel->getGeomObjEntry(shapeName);
245 Handle(AIS_Shape) anObj = getShape(shapeEntry);
246 if ( anObj.IsNull() ) continue;
247 TColStd_IndexedMapOfInteger anIndexes;
248 QSet<int> subIds = entrySubIDs.values(shapeName).toSet();
249 foreach ( int subId, subIds ){
251 anIndexes.Add( subId );
253 if ( anIndexes.Extent() == 0 ) continue;
254 highlightSubShapes( anObj, anIndexes, only );
256 soccViewer->Repaint();
259 void OccGraphicView::addShape(QString& entry, const Handle(AIS_Shape)& ais_shape)
261 if (shapes.contains(entry) || entry.isEmpty())
264 shapes[entry] = ais_shape;
267 Handle(AIS_Shape) OccGraphicView::getShape(const QString& entry)
269 Handle(AIS_Shape) aSh;
271 if (!shapes.contains(entry))
274 return shapes[entry];
277 Handle(AIS_InteractiveContext) OccGraphicView::getContext()
279 Handle (AIS_InteractiveContext) anIC;
280 if (viewWindow == NULL)
283 SUIT_ViewManager* vm = viewWindow->getViewManager();
284 OCCViewer_Viewer* viewer = dynamic_cast<OCCViewer_Viewer*>(vm->getViewModel());
285 Handle (V3d_Viewer) v3d_viewer = viewer->getViewer3d();
286 anIC = viewer->getAISContext();
291 void OccGraphicView::addVertexToCloud(TopoDS_Vertex& vertex)
293 // * add the vertex to the cloud
294 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
295 QString shapeName = "cloud";
296 Handle(AIS_Shape) ais_shape = shapes[docModel->getGeomObjEntry(shapeName)];
297 TopoDS_Shape sh = ais_shape->Shape();
298 BRep_Builder compoundBuilder;
299 compoundBuilder.Add(sh, vertex);
301 // * redisplay the cloud
302 ais_shape->Redisplay();
303 if (viewWindow == NULL)
305 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
311 void OccGraphicView::displayPreview(TopoDS_Shape& shape)
313 if (viewWindow == NULL)
315 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
319 previewShape->Set(shape);
320 // previewShape->SetColor(Quantity_NOC_RED);
321 getContext()->SetColor( previewShape, Quantity_NOC_RED );
322 previewShape->Redisplay();
327 Handle(AIS_Shape) OccGraphicView::getPreviewShape()
329 TopoDS_Shape shapeToPreview;
330 previewShape->Set(shapeToPreview);