1 // Copyright (C) 2009-2016 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, or (at your option) any later version.
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
21 #include "HEXABLOCKGUI_OccGraphicView.hxx"
22 #include "HEXABLOCKGUI.hxx"
23 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
25 #include <SOCC_ViewModel.h>
26 #include <SUIT_ViewManager.h>
30 using namespace HEXABLOCK::GUI;
32 // -----------------------------------------------------------------------
33 // OccGraphicView implementation
34 // -----------------------------------------------------------------------
36 OccGraphicView::OccGraphicView( OCCViewer_ViewWindow* view, QWidget* parent ):
39 selectionMode(TopAbs_SHAPE)
41 TopoDS_Shape shapeToPreview;
42 previewShape = new AIS_Shape(shapeToPreview);
43 // previewShape->SetColor(Quantity_NOC_RED);
44 getContext()->SetColor( previewShape, Quantity_NOC_RED, Standard_True );
47 void OccGraphicView::setSelectionMode(TopAbs_ShapeEnum mode)
49 if (viewWindow == NULL || selectionMode == mode)
52 HEXABLOCKGUI::selectionMgr()->clearSelected();
58 void OccGraphicView::setSelectionMode(const QModelIndex& eltIndex)
61 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
62 if ( !treeVariant.isValid() ) return;
63 int eltType = treeVariant.toInt();
66 case VERTEX_TREE : setSelectionMode(TopAbs_VERTEX); break;
67 case VERTEX_DIR_TREE : setSelectionMode(TopAbs_VERTEX); break;
68 case EDGE_TREE : setSelectionMode(TopAbs_EDGE); break;
69 case EDGE_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
70 case QUAD_TREE : setSelectionMode(TopAbs_FACE); break;
71 case QUAD_DIR_TREE : setSelectionMode(TopAbs_FACE); break;
72 case HEXA_TREE : setSelectionMode(TopAbs_SHAPE); break;
73 case HEXA_DIR_TREE : setSelectionMode(TopAbs_SHAPE); break;
74 case GEOMSHAPE_TREE: setSelectionMode(TopAbs_SHAPE); break;
75 case GEOMSHAPE_DIR_TREE: setSelectionMode(TopAbs_SHAPE); break;
76 case GEOMPOINT_TREE: setSelectionMode(TopAbs_VERTEX); break;
77 case GEOMPOINT_DIR_TREE: setSelectionMode(TopAbs_VERTEX); break;
78 case GEOMEDGE_TREE: setSelectionMode(TopAbs_EDGE); break;
79 case GEOMEDGE_DIR_TREE: setSelectionMode(TopAbs_EDGE); break;
80 case GEOMFACE_TREE: setSelectionMode(TopAbs_FACE); break;
81 case GEOMFACE_DIR_TREE: setSelectionMode(TopAbs_FACE); break;
82 case PROPAGATION_TREE : setSelectionMode(TopAbs_EDGE); break;
83 case PROPAGATION_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
87 void OccGraphicView::getSelected(SALOME_ListIO& selectedObjects)
89 HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects/*, OCCViewer_Viewer::Type()*/ );
91 // SALOME_View* vf = dynamic_cast<SALOME_View*>(HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager()->getViewModel());
92 // if ( vf == NULL ) return;
93 // SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
94 // if (viewer == NULL)
96 // AIS_ListOfInteractive theList;
97 // viewer->getSelectedObjects (theList);
98 // AIS_ListIteratorOfListOfInteractive it (theList);
100 // while (it.More ())
102 // Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast(it.Value()->GetOwner());
103 // if (!anIO.IsNull())
104 // salomeSelected.Append(anIO);
109 void OccGraphicView::clearSelection()
111 if (HEXABLOCKGUI::selectionMgr() == NULL)
114 HEXABLOCKGUI::selectionMgr()->clearSelected();
116 localSelection(TopAbs_SHAPE);
117 selectionMode = TopAbs_SHAPE;
120 void OccGraphicView::localSelection(const int theMode )
122 if (viewWindow == NULL || prs == NULL)
125 // remove all filters from selection
126 LightApp_SelectionMgr* sm = HEXABLOCKGUI::selectionMgr();
129 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
133 vf->LocalSelection( prs, theMode );
136 void OccGraphicView::globalSelection(const bool update )
138 if (viewWindow == NULL)
141 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
142 if ( vf == NULL ) return;
144 // Close local context
145 vf->GlobalSelection( update );
147 // Set selection filters in accordance with current mode
148 LightApp_SelectionMgr* sm = HEXABLOCKGUI::selectionMgr();
154 // Remove filters from AIS_InteractiveContext
155 Handle(AIS_InteractiveContext) ic;
156 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
159 ic = viewer->getAISContext();
165 void OccGraphicView::highlight( const QModelIndex & index, bool only )
168 // getting association(s) from model
169 QMultiMap< QString, int > assocEntrySubIDs;
171 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
172 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
173 if (docModel == NULL) return;
175 assocEntrySubIDs += docModel->getAssocShapesIds(index);
176 highlight( assocEntrySubIDs, only );
180 void OccGraphicView::highlight( const QModelIndexList & indexList, bool only )
183 QMultiMap< QString, int > assocEntrySubIDs;
185 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
186 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
187 PatternDataModel* pModel = HEXABLOCKGUI::currentDocGView->getPatternDataModel();
188 if (docModel == NULL || pModel == NULL) return;
190 foreach( const QModelIndex& anEltIndex, indexList)
192 assocEntrySubIDs += docModel->getAssocShapesIds(anEltIndex);
194 highlight( assocEntrySubIDs, only );
197 void OccGraphicView::highlightSubShapes(const Handle(AIS_Shape)& anObj,
198 const TColStd_IndexedMapOfInteger& aIndexMap, bool only)
200 if (viewWindow == NULL || anObj.IsNull() )
204 Handle (AIS_InteractiveContext) anIC = getContext();
205 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
209 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
210 anIC->SetAutomaticHilight( false );
212 if (only) // * clear current highlighted if asked
213 anIC->ClearSelected( false );
215 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
217 // Get entity owners for all activated selection modes
218 getEntityOwners( anObj, anIC, anAllMap );
220 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
221 indicesToOwners( aIndexMap, anObj->Shape(), anAllMap, aToHiliteMap );
223 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
224 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
226 anIC->SetAutomaticHilight( isAutoHilight );
227 anIC->HilightSelected( false );
230 void OccGraphicView::highlight( const QMultiMap<QString, int>& entrySubIDs, bool only)
233 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL)
236 SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>( viewWindow->getViewManager()->getViewModel() );
237 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
238 if (soccViewer == NULL || docModel == NULL)
241 foreach ( QString shapeName, entrySubIDs.uniqueKeys() )
243 QString shapeEntry = docModel->getGeomObjEntry(shapeName);
244 Handle(AIS_Shape) anObj = getShape(shapeEntry);
245 if ( anObj.IsNull() ) continue;
246 TColStd_IndexedMapOfInteger anIndexes;
247 QSet<int> subIds = entrySubIDs.values(shapeName).toSet();
248 foreach ( int subId, subIds ){
250 anIndexes.Add( subId );
252 if ( anIndexes.Extent() == 0 ) continue;
253 highlightSubShapes( anObj, anIndexes, only );
255 soccViewer->Repaint();
258 void OccGraphicView::addShape(QString& entry, const Handle(AIS_Shape)& ais_shape)
260 if (shapes.contains(entry) || entry.isEmpty())
263 shapes[entry] = ais_shape;
266 Handle(AIS_Shape) OccGraphicView::getShape(const QString& entry)
268 Handle(AIS_Shape) aSh;
270 if (!shapes.contains(entry))
273 return shapes[entry];
276 Handle(AIS_InteractiveContext) OccGraphicView::getContext()
278 Handle (AIS_InteractiveContext) anIC;
279 if (viewWindow == NULL)
282 SUIT_ViewManager* vm = viewWindow->getViewManager();
283 OCCViewer_Viewer* viewer = dynamic_cast<OCCViewer_Viewer*>(vm->getViewModel());
284 Handle (V3d_Viewer) v3d_viewer = viewer->getViewer3d();
285 anIC = viewer->getAISContext();
290 void OccGraphicView::addVertexToCloud(TopoDS_Vertex& vertex)
292 // * add the vertex to the cloud
293 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
294 QString shapeName = "cloud";
295 Handle(AIS_Shape) ais_shape = shapes[docModel->getGeomObjEntry(shapeName)];
296 TopoDS_Shape sh = ais_shape->Shape();
297 BRep_Builder compoundBuilder;
298 compoundBuilder.Add(sh, vertex);
300 // * redisplay the cloud
301 ais_shape->Redisplay();
302 if (viewWindow == NULL)
304 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
310 void OccGraphicView::displayPreview(TopoDS_Shape& shape)
312 if (viewWindow == NULL)
314 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
318 previewShape->Set(shape);
319 // previewShape->SetColor(Quantity_NOC_RED);
320 getContext()->SetColor( previewShape, Quantity_NOC_RED, Standard_True );
321 previewShape->Redisplay();
326 Handle(AIS_Shape) OccGraphicView::getPreviewShape()
328 TopoDS_Shape shapeToPreview;
329 previewShape->Set(shapeToPreview);