0030268: Inspectors - improvements in VInspector plugin
[occt.git] / tools / View / View_Tools.cxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #include <inspector/View_Tools.hxx>
17 #include <inspector/View_Viewer.hxx>
18 #include <inspector/View_Widget.hxx>
19 #include <inspector/View_Window.hxx>
20
21 #include <V3d_View.hxx>
22
23 #include <Standard_WarningsDisable.hxx>
24 #include <QAction>
25 #include <QObject>
26 #include <Standard_WarningsRestore.hxx>
27
28 // =======================================================================
29 // function : CreateAction
30 // purpose :
31 // =======================================================================
32 QAction* View_Tools::CreateAction (const QString& theText, const char* theSlot, QObject* theParent, QObject* theContext)
33 {
34   QAction* anAction = new QAction (theText, theParent);
35   QObject::connect (anAction, SIGNAL (triggered (bool)), theContext, theSlot);
36   return anAction;
37 }
38
39 // =======================================================================
40 // function : SaveState
41 // purpose :
42 // =======================================================================
43 void View_Tools::SaveState (View_Window* theView, QMap<QString, QString>& theItems,
44                             const QString& thePrefix)
45 {
46   QStringList aCameraDirection;
47   Standard_Real aVX, aVY, aVZ;
48   theView->GetView()->GetViewer()->GetView()->Proj (aVX, aVY, aVZ);
49   aCameraDirection << QString::number (aVX) << QString::number (aVY) << QString::number (aVZ);
50
51   theItems[thePrefix + "view_camera_direction"] = aCameraDirection.join (",");
52 }
53
54 // =======================================================================
55 // function : RestoreState
56 // purpose :
57 // =======================================================================
58 bool View_Tools::RestoreState (View_Window* theView, const QString& theKey, const QString& theValue,
59                                const QString& thePrefix)
60 {
61   if (theKey == thePrefix + "view_camera_direction")
62   {
63     QStringList aValues = theValue.split (",");
64     if (aValues.size() == 3)
65     {
66       Standard_Real aVX = aValues.at (0).toDouble();
67       Standard_Real aVY = aValues.at (1).toDouble();
68       Standard_Real aVZ = aValues.at (2).toDouble();
69
70       theView->GetView()->SetInitProj (aVX, aVY, aVZ);
71     }
72   }
73   else
74     return false;
75   return true;
76 }