1 // Copyright (C) 2009-2012 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"
27 #include "MyGEOMBase_Helper.hxx"
28 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
29 #include "HexNewShape.hxx"
30 #include "HexVertexShape.hxx"
31 #include "HexEdgeShape.hxx"
32 #include "HexFaceShape.hxx"
34 #include <SOCC_ViewModel.h>
35 #include <SUIT_ViewManager.h>
39 using namespace HEXABLOCK::GUI;
41 // -----------------------------------------------------------------------
42 // OccGraphicView implementation
43 // -----------------------------------------------------------------------
45 OccGraphicView::OccGraphicView( OCCViewer_ViewWindow* view, QWidget* parent ):
47 selectionMode(TopAbs_SHAPE)
51 void OccGraphicView::setSelectionMode(TopAbs_ShapeEnum mode)
53 if (HEXABLOCKGUI::selectionMgr() == NULL ||
54 HEXABLOCKGUI::geomBaseHelper == NULL || viewWindow == NULL) return;
56 HEXABLOCKGUI::selectionMgr()->clearSelected();
57 HEXABLOCKGUI::geomBaseHelper->globalSelection(viewWindow);
58 // HEXABLOCKGUI::geomBaseHelper->localSelection(GEOM::GEOM_Object::_nil(), mode);
59 HEXABLOCKGUI::geomBaseHelper->localSelection(viewWindow, mode);
64 void OccGraphicView::setSelectionMode(const QModelIndex& eltIndex)
67 QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
68 if ( !treeVariant.isValid() ) return;
69 int eltType = treeVariant.toInt();
72 case VERTEX_TREE : setSelectionMode(TopAbs_VERTEX); break;
73 case VERTEX_DIR_TREE : setSelectionMode(TopAbs_VERTEX); break;
74 case EDGE_TREE : setSelectionMode(TopAbs_EDGE); break;
75 case EDGE_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
76 case QUAD_TREE : setSelectionMode(TopAbs_FACE); break;
77 case QUAD_DIR_TREE : setSelectionMode(TopAbs_FACE); break;
78 case HEXA_TREE : setSelectionMode(TopAbs_SHAPE); break;
79 case HEXA_DIR_TREE : setSelectionMode(TopAbs_SHAPE); break;
80 case GEOMSHAPE_TREE: setSelectionMode(TopAbs_SHAPE); break;
81 case GEOMSHAPE_DIR_TREE: setSelectionMode(TopAbs_SHAPE); break;
82 case GEOMPOINT_TREE: setSelectionMode(TopAbs_VERTEX); break;
83 case GEOMPOINT_DIR_TREE: setSelectionMode(TopAbs_VERTEX); break;
84 case GEOMEDGE_TREE: setSelectionMode(TopAbs_EDGE); break;
85 case GEOMEDGE_DIR_TREE: setSelectionMode(TopAbs_EDGE); break;
86 case GEOMFACE_TREE: setSelectionMode(TopAbs_FACE); break;
87 case GEOMFACE_DIR_TREE: setSelectionMode(TopAbs_FACE); break;
88 case PROPAGATION_TREE : setSelectionMode(TopAbs_EDGE); break;
89 case PROPAGATION_DIR_TREE : setSelectionMode(TopAbs_EDGE); break;
94 void OccGraphicView::clearSelection()
96 if (HEXABLOCKGUI::selectionMgr() == NULL || viewWindow == NULL ||
97 HEXABLOCKGUI::geomBaseHelper == NULL)
100 HEXABLOCKGUI::selectionMgr()->clearSelected();
101 HEXABLOCKGUI::geomBaseHelper->globalSelection(viewWindow);
102 HEXABLOCKGUI::geomBaseHelper->localSelection(viewWindow, TopAbs_SHAPE);
103 selectionMode = TopAbs_SHAPE;
107 void OccGraphicView::highlight( const QModelIndex & index )
110 // getting association(s) from model
111 QMultiMap< QString, int > assocEntrySubIDs;
113 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
114 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
115 if (docModel == NULL) return;
117 assocEntrySubIDs += docModel->getAssocShapesIds(index);
118 highlight( assocEntrySubIDs );
122 void OccGraphicView::highlight( const QModelIndexList & indexList )
125 // QModelIndex index;
126 QMultiMap< QString, int > assocEntrySubIDs;
128 if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
129 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
130 PatternDataModel* pModel = HEXABLOCKGUI::currentDocGView->getPatternDataModel();
131 if (docModel == NULL || pModel == NULL) return;
133 foreach( const QModelIndex& anEltIndex, indexList)
135 // index = pModel->mapToSource(anEltIndex);
136 assocEntrySubIDs += docModel->getAssocShapesIds(anEltIndex);
138 highlight( assocEntrySubIDs );
141 void OccGraphicView::highlight( const QMultiMap<QString, int>& entrySubIDs )
143 if ( viewWindow == NULL ) return;
145 SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>( viewWindow->getViewManager()->getViewModel() );
146 if (!soccViewer) return;
148 DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
149 _PTR(Study) aStudy = GetActiveStudyDocument();
150 if (!aStudy || docModel == NULL) return;
152 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
153 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_nil();
154 HEXABLOCKGUI::geomBaseHelper->erasePreview(true);
156 foreach ( QString shapeName, entrySubIDs.keys() ){
157 QString shapeEntry = docModel->getGeomObjEntry(shapeName);
158 _PTR(SObject) aSChild = aStudy->FindObjectID( shapeEntry.toStdString() );
159 aCorbaObj = corbaObj( aSChild );
160 aGeomObj = GEOM::GEOM_Object::_narrow( aCorbaObj );
161 if ( !CORBA::is_nil(aGeomObj) ){
162 QString objIOR = GEOMBase::GetIORFromObject( aGeomObj._retn() );
163 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR );//, true );
164 if ( !aSh.IsNull() ){
165 TColStd_IndexedMapOfInteger anIndexes;
166 foreach ( int subid, entrySubIDs.values(shapeName) ){
168 anIndexes.Add( subid );
170 if ( anIndexes.Extent() > 0 ){ // if it's a sub-shape
171 aSh->highlightSubShapes( anIndexes, true );
172 // soccViewer->Repaint();
173 } else { // or a main shape
174 // std::cout << "aSh->getIO() => " << aSh->getIO() << std::endl;
175 // soccViewer->setColor( aSh->getIO(), QColor( Qt::red ), true );
176 // soccViewer->switchRepresentation( aSh->getIO(), 2 );
177 // globalSelection();
178 soccViewer->highlight( aSh->getIO(), true, true ); // TODO: not working
183 soccViewer->Repaint();