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 "utilities.h"
24 #include "HEXABLOCKGUI.hxx"
25 #include "HEXABLOCKGUI_DocumentModel.hxx"
26 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
27 #include "HexNewShape.hxx"
28 #include "HexVertexShape.hxx"
29 #include "HexEdgeShape.hxx"
30 #include "HexFaceShape.hxx"
32 #include <SelectMgr_Selection.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 #include <SelectBasics_SensitiveEntity.hxx>
35 #include <StdSelect_BRepOwner.hxx>
38 #include <SOCC_ViewModel.h>
39 #include <SUIT_ViewManager.h>
43 using namespace HEXABLOCK::GUI;
45 // -----------------------------------------------------------------------
46 // OccGraphicView implementation
47 // -----------------------------------------------------------------------
49 OccGraphicView::OccGraphicView( OCCViewer_ViewWindow* view, QWidget* parent ):
52 selectionMode(TopAbs_SHAPE)
54 TopoDS_Shape shapeToPreview;
55 previewShape = new AIS_Shape(shapeToPreview);
56 // previewShape->SetColor(Quantity_NOC_RED);
57 getContext()->SetColor( previewShape, Quantity_NOC_RED );
60 void OccGraphicView::setSelectionMode(TopAbs_ShapeEnum mode)
62 if (viewWindow == NULL || selectionMode == mode)
65 HEXABLOCKGUI::selectionMgr()->clearSelected();
71 void OccGraphicView::setSelectionMode(const QModelIndex& eltIndex)
74 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
75 if ( !treeVariant.isValid() ) return;
76 int eltType = treeVariant.toInt();
79 case VERTEX_TREE : setSelectionMode(TopAbs_VERTEX); break;
80 case VERTEX_DIR_TREE : setSelectionMode(TopAbs_VERTEX); break;
81 case EDGE_TREE : setSelectionMode(TopAbs_EDGE); break;
82 case EDGE_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
83 case QUAD_TREE : setSelectionMode(TopAbs_FACE); break;
84 case QUAD_DIR_TREE : setSelectionMode(TopAbs_FACE); break;
85 case HEXA_TREE : setSelectionMode(TopAbs_SHAPE); break;
86 case HEXA_DIR_TREE : setSelectionMode(TopAbs_SHAPE); break;
87 case GEOMSHAPE_TREE: setSelectionMode(TopAbs_SHAPE); break;
88 case GEOMSHAPE_DIR_TREE: setSelectionMode(TopAbs_SHAPE); break;
89 case GEOMPOINT_TREE: setSelectionMode(TopAbs_VERTEX); break;
90 case GEOMPOINT_DIR_TREE: setSelectionMode(TopAbs_VERTEX); break;
91 case GEOMEDGE_TREE: setSelectionMode(TopAbs_EDGE); break;
92 case GEOMEDGE_DIR_TREE: setSelectionMode(TopAbs_EDGE); break;
93 case GEOMFACE_TREE: setSelectionMode(TopAbs_FACE); break;
94 case GEOMFACE_DIR_TREE: setSelectionMode(TopAbs_FACE); break;
95 case PROPAGATION_TREE : setSelectionMode(TopAbs_EDGE); break;
96 case PROPAGATION_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
100 void OccGraphicView::getSelected(SALOME_ListIO& selectedObjects)
102 HEXABLOCKGUI::selectionMgr()->selectedObjects( selectedObjects/*, OCCViewer_Viewer::Type()*/ );
104 // SALOME_View* vf = dynamic_cast<SALOME_View*>(HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager()->getViewModel());
105 // if ( vf == NULL ) return;
106 // SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
107 // if (viewer == NULL)
109 // AIS_ListOfInteractive theList;
110 // viewer->getSelectedObjects (theList);
111 // AIS_ListIteratorOfListOfInteractive it (theList);
112 // //iterate on list:
113 // while (it.More ())
115 // Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast(it.Value()->GetOwner());
116 // if (!anIO.IsNull())
117 // salomeSelected.Append(anIO);
122 void OccGraphicView::clearSelection()
124 if (HEXABLOCKGUI::selectionMgr() == NULL)
127 HEXABLOCKGUI::selectionMgr()->clearSelected();
129 localSelection(TopAbs_SHAPE);
130 selectionMode = TopAbs_SHAPE;
133 void OccGraphicView::localSelection(const int theMode )
135 if (viewWindow == NULL || prs == NULL)
138 // remove all filters from selection
139 LightApp_SelectionMgr* sm = HEXABLOCKGUI::selectionMgr();
142 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
146 vf->LocalSelection( prs, theMode );
149 void OccGraphicView::globalSelection(const bool update )
151 if (viewWindow == NULL)
154 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
155 if ( vf == NULL ) return;
157 // Close local context
158 vf->GlobalSelection( update );
160 // Set selection filters in accordance with current mode
161 LightApp_SelectionMgr* sm = HEXABLOCKGUI::selectionMgr();
167 // Remove filters from AIS_InteractiveContext
168 Handle(AIS_InteractiveContext) ic;
169 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
172 ic = viewer->getAISContext();
178 void OccGraphicView::highlight( const QModelIndex & index, bool only )
181 // getting association(s) from model
182 QMultiMap< QString, int > assocEntrySubIDs;
184 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
185 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
186 if (docModel == NULL) return;
188 assocEntrySubIDs += docModel->getAssocShapesIds(index);
189 highlight( assocEntrySubIDs, only );
193 void OccGraphicView::highlight( const QModelIndexList & indexList, bool only )
196 QMultiMap< QString, int > assocEntrySubIDs;
198 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
199 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
200 PatternDataModel* pModel = HEXABLOCKGUI::currentDocGView->getPatternDataModel();
201 if (docModel == NULL || pModel == NULL) return;
203 foreach( const QModelIndex& anEltIndex, indexList)
205 assocEntrySubIDs += docModel->getAssocShapesIds(anEltIndex);
207 highlight( assocEntrySubIDs, only );
209 #include <SUIT_Session.h>
210 void OccGraphicView::highlightSubShapes(const Handle(AIS_Shape)& anObj,
211 const TColStd_IndexedMapOfInteger& aIndexMap, bool only)
213 if (viewWindow == NULL || anObj.IsNull() )
217 Handle (AIS_InteractiveContext) anIC = getContext();
218 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
222 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
223 anIC->SetAutomaticHilight( false );
225 if (only) // * clear current highlighted if asked
226 anIC->ClearSelected( false );
228 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
230 // Get entity owners for all activated selection modes
231 getEntityOwners( anObj, anIC, anAllMap );
233 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
234 indicesToOwners( aIndexMap, anObj->Shape(), anAllMap, aToHiliteMap );
236 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
237 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
239 anIC->SetAutomaticHilight( isAutoHilight );
240 anIC->HilightSelected( false );
243 void OccGraphicView::highlight( const QMultiMap<QString, int>& entrySubIDs, bool only)
246 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL)
249 SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>( viewWindow->getViewManager()->getViewModel() );
250 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
251 if (soccViewer == NULL || docModel == NULL)
254 foreach ( QString shapeName, entrySubIDs.uniqueKeys() )
256 QString shapeEntry = docModel->getGeomObjEntry(shapeName);
257 Handle(AIS_Shape) anObj = getShape(shapeEntry);
258 if ( anObj.IsNull() ) continue;
259 TColStd_IndexedMapOfInteger anIndexes;
260 QSet<int> subIds = entrySubIDs.values(shapeName).toSet();
261 foreach ( int subId, subIds ){
263 anIndexes.Add( subId );
265 if ( anIndexes.Extent() == 0 ) continue;
266 highlightSubShapes( anObj, anIndexes, only );
268 soccViewer->Repaint();
271 void OccGraphicView::addShape(QString& entry, const Handle(AIS_Shape)& ais_shape)
273 if (shapes.contains(entry) || entry.isEmpty())
276 shapes[entry] = ais_shape;
279 Handle(AIS_Shape) OccGraphicView::getShape(const QString& entry)
281 Handle(AIS_Shape) aSh;
283 if (!shapes.contains(entry))
286 return shapes[entry];
289 Handle(AIS_InteractiveContext) OccGraphicView::getContext()
291 Handle (AIS_InteractiveContext) anIC;
292 if (viewWindow == NULL)
295 SUIT_ViewManager* vm = viewWindow->getViewManager();
296 OCCViewer_Viewer* viewer = dynamic_cast<OCCViewer_Viewer*>(vm->getViewModel());
297 Handle (V3d_Viewer) v3d_viewer = viewer->getViewer3d();
298 anIC = viewer->getAISContext();
303 void OccGraphicView::addVertexToCloud(TopoDS_Vertex& vertex)
305 // * add the vertex to the cloud
306 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
307 QString shapeName = "cloud";
308 Handle(AIS_Shape) ais_shape = shapes[docModel->getGeomObjEntry(shapeName)];
309 TopoDS_Shape sh = ais_shape->Shape();
310 BRep_Builder compoundBuilder;
311 compoundBuilder.Add(sh, vertex);
313 // * redisplay the cloud
314 ais_shape->Redisplay();
315 if (viewWindow == NULL)
317 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
323 void OccGraphicView::displayPreview(TopoDS_Shape& shape)
325 if (viewWindow == NULL)
327 SALOME_View* vf = dynamic_cast<SALOME_View*>(viewWindow->getViewManager()->getViewModel());
331 previewShape->Set(shape);
332 // previewShape->SetColor(Quantity_NOC_RED);
333 getContext()->SetColor( previewShape, Quantity_NOC_RED );
334 previewShape->Redisplay();
339 Handle(AIS_Shape) OccGraphicView::getPreviewShape()
341 TopoDS_Shape shapeToPreview;
342 previewShape->Set(shapeToPreview);