]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_OccGraphicView.cxx
Salome HOME
Porting to Paraview 3.98.1
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_OccGraphicView.cxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20
21
22 #include "HEXABLOCKGUI_OccGraphicView.hxx"
23 #include "utilities.h"
24 #include "HEXABLOCKGUI.hxx"
25 #include "HEXABLOCKGUI_DocumentModel.hxx"
26 #include "GEOMBase.h"
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"
33
34 #include <SOCC_ViewModel.h>
35 #include <SUIT_ViewManager.h>
36
37
38
39 using namespace HEXABLOCK::GUI;
40
41 // -----------------------------------------------------------------------
42 //          OccGraphicView implementation
43 // -----------------------------------------------------------------------
44
45 OccGraphicView::OccGraphicView( OCCViewer_ViewWindow* view, QWidget* parent ):
46         viewWindow( view ),
47         selectionMode(TopAbs_SHAPE)
48 {
49 }
50
51 void OccGraphicView::setSelectionMode(TopAbs_ShapeEnum mode)
52 {
53     if (HEXABLOCKGUI::selectionMgr() == NULL ||
54             HEXABLOCKGUI::geomBaseHelper == NULL || viewWindow == NULL) return;
55
56     HEXABLOCKGUI::selectionMgr()->clearSelected();
57     HEXABLOCKGUI::geomBaseHelper->globalSelection(viewWindow);
58 //    HEXABLOCKGUI::geomBaseHelper->localSelection(GEOM::GEOM_Object::_nil(), mode);
59     HEXABLOCKGUI::geomBaseHelper->localSelection(viewWindow, mode);
60     selectionMode = mode;
61
62 }
63
64 void OccGraphicView::setSelectionMode(const QModelIndex& eltIndex)
65 {
66
67     QVariant treeVariant = eltIndex.data( HEXA_TREE_ROLE );
68     if ( !treeVariant.isValid() ) return;
69     int eltType = treeVariant.toInt();
70
71     switch ( eltType ){
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;
90     }
91 }
92
93
94 void OccGraphicView::clearSelection()
95 {
96     if (HEXABLOCKGUI::selectionMgr() == NULL || viewWindow == NULL ||
97             HEXABLOCKGUI::geomBaseHelper == NULL)
98         return;
99
100     HEXABLOCKGUI::selectionMgr()->clearSelected();
101     HEXABLOCKGUI::geomBaseHelper->globalSelection(viewWindow);
102     HEXABLOCKGUI::geomBaseHelper->localSelection(viewWindow, TopAbs_SHAPE);
103     selectionMode = TopAbs_SHAPE;
104 }
105
106
107 void OccGraphicView::highlight( const QModelIndex & index )
108 {
109
110     // getting association(s) from model
111     QMultiMap< QString, int >     assocEntrySubIDs;
112
113     if (HEXABLOCKGUI::currentDocGView == NULL || viewWindow == NULL) return;
114     DocumentModel*              docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
115     if (docModel == NULL) return;
116
117     assocEntrySubIDs += docModel->getAssocShapesIds(index);
118     highlight( assocEntrySubIDs );
119 }
120
121
122 void OccGraphicView::highlight( const QModelIndexList & indexList )
123 {
124
125 //    QModelIndex index;
126     QMultiMap< QString, int >     assocEntrySubIDs;
127
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;
132
133     foreach( const QModelIndex& anEltIndex, indexList)
134     {
135 //        index = pModel->mapToSource(anEltIndex);
136        assocEntrySubIDs += docModel->getAssocShapesIds(anEltIndex);
137     }
138     highlight( assocEntrySubIDs );
139 }
140
141 void OccGraphicView::highlight( const QMultiMap<QString, int>&  entrySubIDs )
142 {
143       if ( viewWindow == NULL ) return;
144
145       SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>( viewWindow->getViewManager()->getViewModel() );
146       if (!soccViewer) return;
147
148       DocumentModel* docModel = HEXABLOCKGUI::currentDocGView->getDocumentModel();
149       _PTR(Study) aStudy = GetActiveStudyDocument();
150       if (!aStudy || docModel == NULL) return;
151
152       CORBA::Object_var     aCorbaObj = CORBA::Object::_nil();
153       GEOM::GEOM_Object_var aGeomObj  = GEOM::GEOM_Object::_nil();
154       HEXABLOCKGUI::geomBaseHelper->erasePreview(true);
155
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) ){
167               if ( subid != -1 )
168                 anIndexes.Add( subid );
169             }
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
179             }
180           }
181         }
182       }
183       soccViewer->Repaint();
184
185 }