Salome HOME
refs #1832
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PolylineStyleOp.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_PolylineStyleOp.h>
20 #include <HYDROGUI_PolylineStyleDlg.h>
21 #include <HYDROGUI_UpdateFlags.h>
22 #include <AIS_InteractiveContext.hxx>
23
24 HYDROGUI_PolylineStyleOp::HYDROGUI_PolylineStyleOp( HYDROGUI_Module* theModule )
25   : HYDROGUI_Operation( theModule )
26 {
27 }
28
29 HYDROGUI_PolylineStyleOp::~HYDROGUI_PolylineStyleOp()
30 {
31 }
32
33 HYDROGUI_InputPanel* HYDROGUI_PolylineStyleOp::createInputPanel() const
34 {
35   return new HYDROGUI_PolylineStyleDlg( module() );
36 }
37
38 Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule );
39
40 QList<Handle(HYDROGUI_Arrow)> getSelectedArrows( HYDROGUI_Module* theModule )
41 {
42   QList<Handle(HYDROGUI_Arrow)> arrows;
43   Handle(AIS_InteractiveContext) ctx = getContext( theModule );
44
45   AIS_ListOfInteractive objs;
46   ctx->DisplayedObjects( objs );
47   AIS_ListIteratorOfListOfInteractive it( objs );
48   for( ; it.More(); it.Next() )
49   {
50     Handle(HYDROGUI_Arrow) arrow = Handle(HYDROGUI_Arrow)::DownCast( it.Value() );
51     Handle(AIS_InteractiveObject) obj = arrow;
52     if( !obj.IsNull() && ctx->IsSelected( obj ) )
53       arrows.append( arrow );
54   }
55   return arrows;
56 }
57
58 void HYDROGUI_PolylineStyleOp::startOperation()
59 {
60   HYDROGUI_Operation::startOperation();
61
62   myArrows = getSelectedArrows( module() );
63
64   int aCommonType=-1, aCommonSize=-1;
65   bool isInit = false;
66   foreach( Handle(HYDROGUI_Arrow) arrow, myArrows )
67   {
68     if( !isInit )
69     {
70       aCommonType = arrow->GetType();
71       aCommonSize = arrow->GetSize();
72     }
73     else
74     {
75       if( aCommonType != -1 && aCommonType != arrow->GetType() )
76         aCommonType = -1;
77       if( aCommonSize != -1 && aCommonSize != arrow->GetSize() )
78         aCommonSize = -1;
79     }
80
81     isInit = true;
82   }
83
84   HYDROGUI_PolylineStyleDlg* dlg = dynamic_cast<HYDROGUI_PolylineStyleDlg*>( inputPanel() );
85   dlg->setStyle( aCommonType+1, aCommonSize );
86 }
87
88 bool HYDROGUI_PolylineStyleOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
89                                              QStringList& theBrowseObjectsEntries )
90 {
91   Handle(AIS_InteractiveContext) ctx = getContext( module() );
92
93   int aType, aSize;
94   HYDROGUI_PolylineStyleDlg* dlg = dynamic_cast<HYDROGUI_PolylineStyleDlg*>( inputPanel() );
95   dlg->getStyle( aType, aSize );
96   aType--;
97   
98   foreach( Handle(HYDROGUI_Arrow) arrow, myArrows )
99   {
100     if( aType>=0 )
101       arrow->SetType( (HYDROGUI_Arrow::Type)aType );
102     if( aSize>=0 )
103       arrow->SetSize( aSize );
104     ctx->Redisplay( arrow, Standard_False );
105   }
106   theUpdateFlags = UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
107   return true;
108 }