~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/CommandView.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2002 Jļæ½rgen Riegel <juergen.riegel@web.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
 
 
26
#ifndef _PreComp_
 
27
# include <sstream>
 
28
#endif
 
29
 
 
30
#include "Command.h"
 
31
#include "Action.h"
 
32
#include "Application.h"
 
33
#include "BitmapFactory.h"
 
34
#include "FileDialog.h"
 
35
#include "MainWindow.h"
 
36
#include "Tree.h"
 
37
#include "View.h"
 
38
#include "Document.h"
 
39
#include "Macro.h"
 
40
#include "DlgDisplayPropertiesImp.h"
 
41
#include "DlgSettingsImageImp.h"
 
42
#include "Selection.h"
 
43
#include "SoFCOffscreenRenderer.h"
 
44
#include "View3DInventor.h"
 
45
#include "View3DInventorViewer.h"
 
46
#include "WaitCursor.h"
 
47
#include "ViewProviderMeasureDistance.h"
 
48
#include "SceneInspector.h"
 
49
 
 
50
#include <Base/Console.h>
 
51
#include <Base/Exception.h>
 
52
#include <Base/FileInfo.h>
 
53
#include <Base/Reader.h>
 
54
#include <App/Document.h>
 
55
#include <App/GeoFeature.h>
 
56
#include <App/MeasureDistance.h>
 
57
#include <App/Feature.h>
 
58
 
 
59
#include <QDomDocument>
 
60
#include <QDomElement>
 
61
 
 
62
using namespace Gui;
 
63
using Gui::Dialog::DlgSettingsImageImp;
 
64
 
 
65
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
66
 
 
67
DEF_STD_CMD_AC(StdOrthographicCamera);
 
68
 
 
69
StdOrthographicCamera::StdOrthographicCamera()
 
70
  : Command("Std_OrthographicCamera")
 
71
{
 
72
  sGroup        = QT_TR_NOOP("Standard-View");
 
73
  sMenuText     = QT_TR_NOOP("Orthographic view");
 
74
  sToolTipText  = QT_TR_NOOP("Switches to orthographic view mode");
 
75
  sWhatsThis    = "Std_OrthographicCamera";
 
76
  sStatusTip    = QT_TR_NOOP("Switches to orthographic view mode");
 
77
  iAccel        = Qt::Key_O;
 
78
}
 
79
 
 
80
void StdOrthographicCamera::activated(int iMsg)
 
81
{
 
82
    if (iMsg == 1) {
 
83
        View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
84
        if (view->getViewer()->getCameraType() != SoOrthographicCamera::getClassTypeId())
 
85
            doCommand(Command::Gui,"Gui.activeDocument().activeView().setCameraType(\"Orthographic\")");
 
86
    }
 
87
}
 
88
 
 
89
bool StdOrthographicCamera::isActive(void)
 
90
{
 
91
  View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
92
  if ( view )
 
93
  {
 
94
    // update the action group if needed
 
95
    bool check = _pcAction->isChecked();
 
96
    bool mode = view->getViewer()->getCameraType() == SoOrthographicCamera::getClassTypeId();
 
97
    if (mode != check)
 
98
        _pcAction->setChecked(mode);
 
99
 
 
100
    return true;
 
101
  }
 
102
 
 
103
  return false;
 
104
}
 
105
 
 
106
Action * StdOrthographicCamera::createAction(void)
 
107
{
 
108
  Action *pcAction = Command::createAction();
 
109
  pcAction->setCheckable( true );
 
110
  return pcAction;
 
111
}
 
112
 
 
113
DEF_STD_CMD_AC(StdPerspectiveCamera);
 
114
 
 
115
StdPerspectiveCamera::StdPerspectiveCamera()
 
116
  : Command("Std_PerspectiveCamera")
 
117
{
 
118
  sGroup        = QT_TR_NOOP("Standard-View");
 
119
  sMenuText     = QT_TR_NOOP("Perspective view");
 
120
  sToolTipText  = QT_TR_NOOP("Switches to perspective view mode");
 
121
  sWhatsThis    = "Std_PerspectiveCamera";
 
122
  sStatusTip    = QT_TR_NOOP("Switches to perspective view mode");
 
123
  iAccel        = Qt::Key_P;
 
124
}
 
125
 
 
126
void StdPerspectiveCamera::activated(int iMsg)
 
127
{
 
128
    if (iMsg == 1) {
 
129
        View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
130
        if (view->getViewer()->getCameraType() != SoPerspectiveCamera::getClassTypeId())
 
131
            doCommand(Command::Gui,"Gui.activeDocument().activeView().setCameraType(\"Perspective\")");
 
132
    }
 
133
}
 
134
 
 
135
bool StdPerspectiveCamera::isActive(void)
 
136
{
 
137
  View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
138
  if ( view )
 
139
  {
 
140
    // update the action group if needed
 
141
    bool check = _pcAction->isChecked();
 
142
    bool mode = view->getViewer()->getCameraType() == SoPerspectiveCamera::getClassTypeId();
 
143
    if (mode != check)
 
144
        _pcAction->setChecked(mode);
 
145
 
 
146
    return true;
 
147
  }
 
148
 
 
149
  return false;
 
150
}
 
151
 
 
152
Action * StdPerspectiveCamera::createAction(void)
 
153
{
 
154
  Action *pcAction = Command::createAction();
 
155
  pcAction->setCheckable( true );
 
156
  return pcAction;
 
157
}
 
158
 
 
159
//===========================================================================
 
160
// Std_FreezeViews
 
161
//===========================================================================
 
162
class StdCmdFreezeViews : public Gui::Command
 
163
{
 
164
public:
 
165
    StdCmdFreezeViews();
 
166
    virtual ~StdCmdFreezeViews(){}
 
167
 
 
168
protected: 
 
169
    virtual void activated(int iMsg);
 
170
    virtual bool isActive(void);
 
171
    virtual Action * createAction(void);
 
172
    virtual void languageChange();
 
173
 
 
174
private:
 
175
    void onSaveViews();
 
176
    void onRestoreViews();
 
177
 
 
178
private:
 
179
    const int maxViews;
 
180
    int savedViews;
 
181
    int offset;
 
182
    QAction* saveView;
 
183
    QAction* freezeView;
 
184
    QAction* clearView;
 
185
    QAction* separator;
 
186
};
 
187
 
 
188
StdCmdFreezeViews::StdCmdFreezeViews()
 
189
  : Command("Std_FreezeViews"), maxViews(50), savedViews(0)
 
190
{
 
191
  sGroup        = QT_TR_NOOP("Standard-View");
 
192
  sMenuText     = QT_TR_NOOP("Freeze display");
 
193
  sToolTipText  = QT_TR_NOOP("Freezes the current view position");
 
194
  sWhatsThis    = "Std_FreezeViews";
 
195
  sStatusTip    = QT_TR_NOOP("Freezes the current view position");
 
196
  iAccel        = Qt::SHIFT+Qt::Key_F;
 
197
}
 
198
 
 
199
Action * StdCmdFreezeViews::createAction(void)
 
200
{
 
201
  ActionGroup* pcAction = new ActionGroup(this, getMainWindow());
 
202
  pcAction->setDropDownMenu(true);
 
203
  pcAction->setText(QObject::tr(sMenuText));
 
204
  pcAction->setToolTip(QObject::tr(sToolTipText));
 
205
  pcAction->setStatusTip(QObject::tr(sStatusTip));
 
206
  pcAction->setWhatsThis(QObject::tr(sWhatsThis));
 
207
  
 
208
  // add the action items
 
209
  saveView = pcAction->addAction(QObject::tr("Save views..."));
 
210
  pcAction->addAction(QObject::tr("Load views..."));
 
211
  pcAction->addAction(QString::fromAscii(""))->setSeparator(true);
 
212
  freezeView = pcAction->addAction(QObject::tr("Freeze view"));
 
213
  freezeView->setShortcut(iAccel);
 
214
  clearView = pcAction->addAction(QObject::tr("Clear views"));
 
215
  separator = pcAction->addAction(QString::fromAscii(""));
 
216
  separator->setSeparator(true);
 
217
  offset = pcAction->actions().count();
 
218
 
 
219
  // allow up to 50 views
 
220
  for (int i=0; i<maxViews; i++)
 
221
      pcAction->addAction(QString::fromAscii(""))->setVisible(false);
 
222
 
 
223
  return pcAction;
 
224
}
 
225
 
 
226
void StdCmdFreezeViews::activated(int iMsg)
 
227
{
 
228
  ActionGroup* pcAction = qobject_cast<ActionGroup*>(_pcAction);
 
229
  
 
230
  if ( iMsg == 0 ) {
 
231
      onSaveViews();
 
232
  } else if ( iMsg == 1 ) {
 
233
      onRestoreViews();
 
234
  } else if ( iMsg == 3 ) {
 
235
    // Create a new view
 
236
    const char* ppReturn=0;
 
237
    getGuiApplication()->sendMsgToActiveView("GetCamera",&ppReturn);
 
238
 
 
239
    QList<QAction*> acts = pcAction->actions();
 
240
    int index = 0;
 
241
    for (QList<QAction*>::ConstIterator it = acts.begin()+offset; it != acts.end(); ++it, index++) {
 
242
      if ( !(*it)->isVisible() ) {
 
243
        savedViews++;
 
244
        QString viewnr = QString(QObject::tr("Restore view &%1")).arg(index+1);
 
245
        (*it)->setText(viewnr);
 
246
        (*it)->setToolTip(QString::fromAscii(ppReturn));
 
247
        (*it)->setVisible(true);
 
248
        if ( index < 9 ) {
 
249
          int accel = Qt::CTRL+Qt::Key_1;
 
250
          (*it)->setShortcut(accel+index);
 
251
        }
 
252
        break;
 
253
      }
 
254
    }
 
255
  } else if ( iMsg == 4 ) {
 
256
    savedViews = 0;
 
257
    QList<QAction*> acts = pcAction->actions();   
 
258
    for (QList<QAction*>::ConstIterator it = acts.begin()+offset; it != acts.end(); ++it)
 
259
      (*it)->setVisible(false);
 
260
  } else if ( iMsg >= offset ) {
 
261
    // Activate a view
 
262
    QList<QAction*> acts = pcAction->actions();
 
263
    QString data = acts[iMsg]->toolTip();
 
264
    QString send = QString::fromAscii("SetCamera %1").arg(data);
 
265
    getGuiApplication()->sendMsgToActiveView(send.toAscii());
 
266
  }
 
267
}
 
268
 
 
269
void StdCmdFreezeViews::onSaveViews()
 
270
{
 
271
    // Save the views to an XML file
 
272
    QString fn = FileDialog::getSaveFileName(getMainWindow(), QObject::tr("Save frozen views"),
 
273
                                             QString(), QObject::tr("Frozen views (*.cam)"));
 
274
    if (fn.isEmpty())
 
275
        return;
 
276
    QFile file(fn);
 
277
    if (file.open(QFile::WriteOnly))
 
278
    {
 
279
        QTextStream str(&file);
 
280
        ActionGroup* pcAction = qobject_cast<ActionGroup*>(_pcAction);
 
281
        QList<QAction*> acts = pcAction->actions();      
 
282
        str << "<?xml version='1.0' encoding='utf-8'?>" << endl
 
283
            << "<FrozenViews SchemaVersion=\"1\">" << endl;
 
284
        str << "  <Views Count=\"" << savedViews <<"\">" << endl;
 
285
 
 
286
        for (QList<QAction*>::ConstIterator it = acts.begin()+offset; it != acts.end(); ++it) {
 
287
            if ( !(*it)->isVisible() )
 
288
                break;
 
289
            QString data = (*it)->toolTip();
 
290
 
 
291
            // remove the first line because it's a comment like '#Inventor V2.1 ascii'
 
292
            QString viewPos;
 
293
            if ( !data.isEmpty() ) {
 
294
                QStringList lines = data.split(QString::fromAscii("\n"));
 
295
                if ( lines.size() > 1 ) {
 
296
                    lines.pop_front();
 
297
                    viewPos = lines.join(QString::fromAscii(" "));
 
298
                }
 
299
            }
 
300
 
 
301
            str << "    <Camera settings=\"" << viewPos.toAscii().constData() << "\"/>" << endl;
 
302
        }
 
303
 
 
304
        str << "  </Views>" << endl;
 
305
        str << "</FrozenViews>" << endl;
 
306
    }
 
307
}
 
308
 
 
309
void StdCmdFreezeViews::onRestoreViews()
 
310
{
 
311
    // Should we clear the already saved views
 
312
    if ( savedViews > 0 ) {
 
313
        int ret = QMessageBox::question(getMainWindow(), QObject::tr("Restore views"), 
 
314
            QObject::tr("Importing the restored views would clear the already stored views.\n"
 
315
                        "Do you want to continue?"), QMessageBox::Yes|QMessageBox::Default,
 
316
                                                     QMessageBox::No|QMessageBox::Escape); 
 
317
        if (ret!=QMessageBox::Yes)
 
318
            return;
 
319
    }
 
320
 
 
321
    // Restore the views from an XML file
 
322
    QString fn = FileDialog::getOpenFileName(getMainWindow(), QObject::tr("Restore frozen views"),
 
323
                                             QString(), QObject::tr("Frozen views (*.cam)"));
 
324
    if (fn.isEmpty())
 
325
        return;
 
326
    QFile file(fn);
 
327
    if (!file.open(QFile::ReadOnly)) {
 
328
        QMessageBox::critical(getMainWindow(), QObject::tr("Restore views"),
 
329
            QObject::tr("Cannot open file '%1'.").arg(fn));
 
330
        return;
 
331
    }
 
332
 
 
333
    QDomDocument xmlDocument;
 
334
    QString errorStr;
 
335
    int errorLine;
 
336
    int errorColumn;
 
337
 
 
338
    // evaluate the XML content
 
339
    if (!xmlDocument.setContent(&file, true, &errorStr, &errorLine, &errorColumn)) {
 
340
        std::cerr << "Parse error in XML content at line " << errorLine
 
341
                  << ", column " << errorColumn << ": "
 
342
                  << (const char*)errorStr.toAscii() << std::endl;
 
343
        return;
 
344
    }
 
345
 
 
346
    // get the root element
 
347
    QDomElement root = xmlDocument.documentElement();
 
348
    if (root.tagName() != QLatin1String("FrozenViews")) {
 
349
        std::cerr << "Unexpected XML structure" << std::endl;
 
350
        return;
 
351
    }
 
352
 
 
353
    bool ok;
 
354
    int scheme = root.attribute(QString::fromAscii("SchemaVersion")).toInt(&ok);
 
355
    if (!ok) return;
 
356
    // SchemeVersion "1"
 
357
    if (scheme == 1) {
 
358
        // read the views, ignore the attribute 'Count'
 
359
        QDomElement child = root.firstChildElement(QString::fromAscii("Views"));
 
360
        QDomElement views = child.firstChildElement(QString::fromAscii("Camera"));
 
361
        QStringList cameras;
 
362
        while (!views.isNull()) {
 
363
            QString setting = views.attribute(QString::fromAscii("settings"));
 
364
            cameras << setting;
 
365
            views = views.nextSiblingElement(QString::fromAscii("Camera"));
 
366
        }
 
367
 
 
368
        // use this rather than the attribute 'Count' because it could be
 
369
        // changed from outside
 
370
        int ct = cameras.count();
 
371
        ActionGroup* pcAction = qobject_cast<ActionGroup*>(_pcAction);
 
372
        QList<QAction*> acts = pcAction->actions();      
 
373
 
 
374
        int numRestoredViews = std::min<int>(ct, acts.size()-offset);
 
375
        savedViews = numRestoredViews;
 
376
 
 
377
        if (numRestoredViews > 0)
 
378
            separator->setVisible(true);
 
379
        for(int i=0; i<numRestoredViews; i++) {
 
380
            QString setting = cameras[i];
 
381
            QString viewnr = QString(QObject::tr("Restore view &%1")).arg(i+1);
 
382
            acts[i+offset]->setText(viewnr);
 
383
            acts[i+offset]->setToolTip(setting);
 
384
            acts[i+offset]->setVisible(true);
 
385
            if ( i < 9 ) {
 
386
                int accel = Qt::CTRL+Qt::Key_1;
 
387
                acts[i+offset]->setShortcut(accel+i);
 
388
            }
 
389
        }
 
390
 
 
391
        // if less views than actions
 
392
        for (int index = numRestoredViews+offset; index < acts.count(); index++)
 
393
            acts[index]->setVisible(false);
 
394
    }
 
395
}
 
396
 
 
397
bool StdCmdFreezeViews::isActive(void)
 
398
{
 
399
  View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
400
  if (view) {
 
401
    saveView->setEnabled(savedViews > 0);
 
402
    freezeView->setEnabled(savedViews < maxViews);
 
403
    clearView->setEnabled(savedViews > 0);
 
404
    separator->setVisible(savedViews > 0);
 
405
    return true;
 
406
  } else {
 
407
    separator->setVisible(savedViews > 0);
 
408
  }
 
409
 
 
410
  return false;
 
411
}
 
412
 
 
413
void StdCmdFreezeViews::languageChange()
 
414
{
 
415
  Command::languageChange();
 
416
 
 
417
  if (!_pcAction)
 
418
    return;
 
419
  ActionGroup* pcAction = qobject_cast<ActionGroup*>(_pcAction);
 
420
  QList<QAction*> acts = pcAction->actions();
 
421
  acts[0]->setText(QObject::tr("Save views..."));
 
422
  acts[1]->setText(QObject::tr("Load views..."));
 
423
  acts[3]->setText(QObject::tr("Freeze view"));
 
424
  acts[4]->setText(QObject::tr("Clear views"));
 
425
  int index=1;
 
426
  for (QList<QAction*>::ConstIterator it = acts.begin()+5; it != acts.end(); ++it, index++) {
 
427
    if ( (*it)->isVisible() ) {
 
428
      QString viewnr = QString(QObject::tr("Restore view &%1")).arg(index);
 
429
      (*it)->setText(viewnr);
 
430
    }
 
431
  }
 
432
}
 
433
 
 
434
//===========================================================================
 
435
// Std_ToggleClipPlane
 
436
//===========================================================================
 
437
 
 
438
DEF_STD_CMD_AC(StdCmdToggleClipPlane);
 
439
 
 
440
StdCmdToggleClipPlane::StdCmdToggleClipPlane()
 
441
  : Command("Std_ToggleClipPlane")
 
442
{
 
443
  sGroup        = QT_TR_NOOP("Standard-View");
 
444
  sMenuText     = QT_TR_NOOP("Clipping plane");
 
445
  sToolTipText  = QT_TR_NOOP("Toggles clipping plane for active view");
 
446
  sWhatsThis    = "Std_ToggleClipPlane";
 
447
  sStatusTip    = QT_TR_NOOP("Toggles clipping plane for active view");
 
448
}
 
449
 
 
450
Action * StdCmdToggleClipPlane::createAction(void)
 
451
{
 
452
  Action *pcAction = (Action*)Command::createAction();
 
453
  pcAction->setCheckable( true );
 
454
  return pcAction;
 
455
}
 
456
 
 
457
void StdCmdToggleClipPlane::activated(int iMsg)
 
458
{
 
459
  View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
460
  if (view) {
 
461
    if (iMsg > 0 && !view->hasClippingPlane())
 
462
      view->toggleClippingPlane();
 
463
    else if (iMsg == 0 && view->hasClippingPlane())
 
464
      view->toggleClippingPlane();
 
465
  }
 
466
}
 
467
 
 
468
bool StdCmdToggleClipPlane::isActive(void)
 
469
{
 
470
  View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
471
  if (view){
 
472
    Action* action = qobject_cast<Action*>(_pcAction);
 
473
    if (action->isChecked() != view->hasClippingPlane())
 
474
      action->setChecked(view->hasClippingPlane());
 
475
    return true;
 
476
  } else {
 
477
    Action* action = qobject_cast<Action*>(_pcAction);
 
478
    if (action->isChecked())
 
479
      action->setChecked(false);
 
480
    return false;
 
481
  }
 
482
}
 
483
 
 
484
//===========================================================================
 
485
// Std_ToggleVisibility
 
486
//===========================================================================
 
487
DEF_STD_CMD_A(StdCmdToggleVisibility);
 
488
 
 
489
StdCmdToggleVisibility::StdCmdToggleVisibility()
 
490
  : Command("Std_ToggleVisibility")
 
491
{
 
492
    sGroup        = QT_TR_NOOP("Standard-View");
 
493
    sMenuText     = QT_TR_NOOP("Toggle visibility");
 
494
    sToolTipText  = QT_TR_NOOP("Toggles visibility");
 
495
    sStatusTip    = QT_TR_NOOP("Toggles visibility");
 
496
    sWhatsThis    = "Std_ToggleVisibility";
 
497
    iAccel        = Qt::Key_Space;
 
498
}
 
499
 
 
500
void StdCmdToggleVisibility::activated(int iMsg)
 
501
{
 
502
    // go through all documents
 
503
    const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
 
504
    for (std::vector<App::Document*>::const_iterator it = docs.begin(); it != docs.end(); ++it) {
 
505
        Document *pcDoc = Application::Instance->getDocument(*it);
 
506
        const std::vector<App::DocumentObject*> sel = Selection().getObjectsOfType
 
507
            (App::DocumentObject::getClassTypeId(), (*it)->getName());
 
508
        for(std::vector<App::DocumentObject*>::const_iterator ft=sel.begin();ft!=sel.end();ft++) {
 
509
            if (pcDoc && pcDoc->isShow((*ft)->getNameInDocument()))
 
510
                doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=False"
 
511
                             , (*it)->getName(), (*ft)->getNameInDocument());
 
512
            else
 
513
                doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=True"
 
514
                             , (*it)->getName(), (*ft)->getNameInDocument());
 
515
        }
 
516
    }
 
517
}
 
518
 
 
519
bool StdCmdToggleVisibility::isActive(void)
 
520
{
 
521
    return (Gui::Selection().size() != 0);
 
522
}
 
523
 
 
524
//===========================================================================
 
525
// Std_ShowSelection
 
526
//===========================================================================
 
527
DEF_STD_CMD_A(StdCmdShowSelection);
 
528
 
 
529
StdCmdShowSelection::StdCmdShowSelection()
 
530
  : Command("Std_ShowSelection")
 
531
{
 
532
    sGroup        = QT_TR_NOOP("Standard-View");
 
533
    sMenuText     = QT_TR_NOOP("Show selection");
 
534
    sToolTipText  = QT_TR_NOOP("Show all selected objects");
 
535
    sStatusTip    = QT_TR_NOOP("Show all selected objects");
 
536
    sWhatsThis    = "Std_ShowSelection";
 
537
}
 
538
 
 
539
void StdCmdShowSelection::activated(int iMsg)
 
540
{
 
541
    // go through all documents
 
542
    const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
 
543
    for (std::vector<App::Document*>::const_iterator it = docs.begin(); it != docs.end(); ++it) {
 
544
        const std::vector<App::DocumentObject*> sel = Selection().getObjectsOfType
 
545
            (App::DocumentObject::getClassTypeId(), (*it)->getName());
 
546
        for(std::vector<App::DocumentObject*>::const_iterator ft=sel.begin();ft!=sel.end();ft++) {
 
547
            doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=True"
 
548
                         , (*it)->getName(), (*ft)->getNameInDocument());
 
549
        }
 
550
    }
 
551
}
 
552
 
 
553
bool StdCmdShowSelection::isActive(void)
 
554
{
 
555
    return (Gui::Selection().size() != 0);
 
556
}
 
557
 
 
558
//===========================================================================
 
559
// Std_HideSelection
 
560
//===========================================================================
 
561
DEF_STD_CMD_A(StdCmdHideSelection);
 
562
 
 
563
StdCmdHideSelection::StdCmdHideSelection()
 
564
  : Command("Std_HideSelection")
 
565
{
 
566
    sGroup        = QT_TR_NOOP("Standard-View");
 
567
    sMenuText     = QT_TR_NOOP("Hide selection");
 
568
    sToolTipText  = QT_TR_NOOP("Hide all selected objects");
 
569
    sStatusTip    = QT_TR_NOOP("Hide all selected objects");
 
570
    sWhatsThis    = "Std_HideSelection";
 
571
}
 
572
 
 
573
void StdCmdHideSelection::activated(int iMsg)
 
574
{
 
575
    // go through all documents
 
576
    const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
 
577
    for (std::vector<App::Document*>::const_iterator it = docs.begin(); it != docs.end(); ++it) {
 
578
        const std::vector<App::DocumentObject*> sel = Selection().getObjectsOfType
 
579
            (App::DocumentObject::getClassTypeId(), (*it)->getName());
 
580
        for(std::vector<App::DocumentObject*>::const_iterator ft=sel.begin();ft!=sel.end();ft++) {
 
581
            doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=False"
 
582
                         , (*it)->getName(), (*ft)->getNameInDocument());
 
583
        }
 
584
    }
 
585
}
 
586
 
 
587
bool StdCmdHideSelection::isActive(void)
 
588
{
 
589
    return (Gui::Selection().size() != 0);
 
590
}
 
591
 
 
592
//===========================================================================
 
593
// Std_ToggleObjects
 
594
//===========================================================================
 
595
DEF_STD_CMD_A(StdCmdToggleObjects);
 
596
 
 
597
StdCmdToggleObjects::StdCmdToggleObjects()
 
598
  : Command("Std_ToggleObjects")
 
599
{
 
600
    sGroup        = QT_TR_NOOP("Standard-View");
 
601
    sMenuText     = QT_TR_NOOP("Toggle all objects");
 
602
    sToolTipText  = QT_TR_NOOP("Toggles visibility of all objects in the active document");
 
603
    sStatusTip    = QT_TR_NOOP("Toggles visibility of all objects in the active document");
 
604
    sWhatsThis    = "Std_ToggleObjects";
 
605
}
 
606
 
 
607
void StdCmdToggleObjects::activated(int iMsg)
 
608
{
 
609
    // go through active document
 
610
    Gui::Document* doc = Application::Instance->activeDocument();
 
611
    App::Document* app = doc->getDocument();
 
612
    const std::vector<App::DocumentObject*> obj = app->getObjectsOfType
 
613
        (App::DocumentObject::getClassTypeId());
 
614
 
 
615
    for (std::vector<App::DocumentObject*>::const_iterator it=obj.begin();it!=obj.end();++it) {
 
616
        if (doc && doc->isShow((*it)->getNameInDocument()))
 
617
            doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=False"
 
618
                         , app->getName(), (*it)->getNameInDocument());
 
619
        else
 
620
            doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=True"
 
621
                         , app->getName(), (*it)->getNameInDocument());
 
622
    }
 
623
}
 
624
 
 
625
bool StdCmdToggleObjects::isActive(void)
 
626
{
 
627
    return App::GetApplication().getActiveDocument();
 
628
}
 
629
 
 
630
//===========================================================================
 
631
// Std_ShowObjects
 
632
//===========================================================================
 
633
DEF_STD_CMD_A(StdCmdShowObjects);
 
634
 
 
635
StdCmdShowObjects::StdCmdShowObjects()
 
636
  : Command("Std_ShowObjects")
 
637
{
 
638
    sGroup        = QT_TR_NOOP("Standard-View");
 
639
    sMenuText     = QT_TR_NOOP("Show all objects");
 
640
    sToolTipText  = QT_TR_NOOP("Show all objects in the document");
 
641
    sStatusTip    = QT_TR_NOOP("Show all objects in the document");
 
642
    sWhatsThis    = "Std_ShowObjects";
 
643
}
 
644
 
 
645
void StdCmdShowObjects::activated(int iMsg)
 
646
{
 
647
    // go through active document
 
648
    Gui::Document* doc = Application::Instance->activeDocument();
 
649
    App::Document* app = doc->getDocument();
 
650
    const std::vector<App::DocumentObject*> obj = app->getObjectsOfType
 
651
        (App::DocumentObject::getClassTypeId());
 
652
 
 
653
    for (std::vector<App::DocumentObject*>::const_iterator it=obj.begin();it!=obj.end();++it) {
 
654
        doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=True"
 
655
                     , app->getName(), (*it)->getNameInDocument());
 
656
    }
 
657
}
 
658
 
 
659
bool StdCmdShowObjects::isActive(void)
 
660
{
 
661
    return App::GetApplication().getActiveDocument();
 
662
}
 
663
 
 
664
//===========================================================================
 
665
// Std_HideObjects
 
666
//===========================================================================
 
667
DEF_STD_CMD_A(StdCmdHideObjects);
 
668
 
 
669
StdCmdHideObjects::StdCmdHideObjects()
 
670
  : Command("Std_HideObjects")
 
671
{
 
672
    sGroup        = QT_TR_NOOP("Standard-View");
 
673
    sMenuText     = QT_TR_NOOP("Hide all objects");
 
674
    sToolTipText  = QT_TR_NOOP("Hide all objects in the document");
 
675
    sStatusTip    = QT_TR_NOOP("Hide all objects in the document");
 
676
    sWhatsThis    = "Std_HideObjects";
 
677
}
 
678
 
 
679
void StdCmdHideObjects::activated(int iMsg)
 
680
{
 
681
    // go through active document
 
682
    Gui::Document* doc = Application::Instance->activeDocument();
 
683
    App::Document* app = doc->getDocument();
 
684
    const std::vector<App::DocumentObject*> obj = app->getObjectsOfType
 
685
        (App::DocumentObject::getClassTypeId());
 
686
 
 
687
    for (std::vector<App::DocumentObject*>::const_iterator it=obj.begin();it!=obj.end();++it) {
 
688
        doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=False"
 
689
                     , app->getName(), (*it)->getNameInDocument());
 
690
    }
 
691
}
 
692
 
 
693
bool StdCmdHideObjects::isActive(void)
 
694
{
 
695
    return App::GetApplication().getActiveDocument();
 
696
}
 
697
 
 
698
//===========================================================================
 
699
// Std_SetAppearance
 
700
//===========================================================================
 
701
DEF_STD_CMD_A(StdCmdSetAppearance);
 
702
 
 
703
StdCmdSetAppearance::StdCmdSetAppearance()
 
704
  : Command("Std_SetAppearance")
 
705
{
 
706
    sGroup        = QT_TR_NOOP("Standard-View");
 
707
    sMenuText     = QT_TR_NOOP("Appearance...");
 
708
    sToolTipText  = QT_TR_NOOP("Sets the display properties of the selected object");
 
709
    sWhatsThis    = "Std_SetAppearance";
 
710
    sStatusTip    = QT_TR_NOOP("Sets the display properties of the selected object");
 
711
    sPixmap       = "Std_Tool1";
 
712
    iAccel        = Qt::CTRL+Qt::Key_D;
 
713
}
 
714
 
 
715
void StdCmdSetAppearance::activated(int iMsg)
 
716
{
 
717
    static QPointer<QDialog> dlg = 0;
 
718
    if (!dlg)
 
719
        dlg = new Gui::Dialog::DlgDisplayPropertiesImp(getMainWindow());
 
720
    dlg->setModal(false);
 
721
    dlg->setAttribute(Qt::WA_DeleteOnClose);
 
722
    dlg->show();
 
723
}
 
724
 
 
725
bool StdCmdSetAppearance::isActive(void)
 
726
{
 
727
    return Gui::Selection().size() != 0;
 
728
}
 
729
 
 
730
//===========================================================================
 
731
// Std_ViewBottom
 
732
//===========================================================================
 
733
DEF_3DV_CMD(StdCmdViewBottom)
 
734
 
 
735
StdCmdViewBottom::StdCmdViewBottom()
 
736
  : Command("Std_ViewBottom")
 
737
{
 
738
  sGroup        = QT_TR_NOOP("Standard-View");
 
739
  sMenuText     = QT_TR_NOOP("Bottom");
 
740
  sToolTipText  = QT_TR_NOOP("Set to bottom view");
 
741
  sWhatsThis    = "Std_ViewXX";
 
742
  sStatusTip    = QT_TR_NOOP("Set to bottom view");
 
743
  sPixmap       = "view-bottom";
 
744
  iAccel        = Qt::Key_5;
 
745
}
 
746
 
 
747
void StdCmdViewBottom::activated(int iMsg)
 
748
{
 
749
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewBottom()");
 
750
}
 
751
 
 
752
//===========================================================================
 
753
// Std_ViewFront
 
754
//===========================================================================
 
755
DEF_3DV_CMD(StdCmdViewFront);
 
756
 
 
757
StdCmdViewFront::StdCmdViewFront()
 
758
  : Command("Std_ViewFront")
 
759
{
 
760
  sGroup        = QT_TR_NOOP("Standard-View");
 
761
  sMenuText     = QT_TR_NOOP("Front");
 
762
  sToolTipText  = QT_TR_NOOP("Set to front view");
 
763
  sWhatsThis    = "Std_ViewXX";
 
764
  sStatusTip    = QT_TR_NOOP("Set to front view");
 
765
  sPixmap       = "view-front";
 
766
  iAccel        = Qt::Key_1;
 
767
}
 
768
 
 
769
void StdCmdViewFront::activated(int iMsg)
 
770
{
 
771
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewFront()");
 
772
}
 
773
 
 
774
//===========================================================================
 
775
// Std_ViewLeft
 
776
//===========================================================================
 
777
DEF_3DV_CMD(StdCmdViewLeft);
 
778
 
 
779
StdCmdViewLeft::StdCmdViewLeft()
 
780
  : Command("Std_ViewLeft")
 
781
{
 
782
  sGroup        = QT_TR_NOOP("Standard-View");
 
783
  sMenuText     = QT_TR_NOOP("Left");
 
784
  sToolTipText  = QT_TR_NOOP("Set to left view");
 
785
  sWhatsThis    = "Std_ViewXX";
 
786
  sStatusTip    = QT_TR_NOOP("Set to left view");
 
787
  sPixmap       = "view-left";
 
788
  iAccel        = Qt::Key_6;
 
789
}
 
790
 
 
791
void StdCmdViewLeft::activated(int iMsg)
 
792
{
 
793
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewLeft()");
 
794
}
 
795
 
 
796
//===========================================================================
 
797
// Std_ViewRear
 
798
//===========================================================================
 
799
DEF_3DV_CMD(StdCmdViewRear);
 
800
 
 
801
StdCmdViewRear::StdCmdViewRear()
 
802
  : Command("Std_ViewRear")
 
803
{
 
804
  sGroup        = QT_TR_NOOP("Standard-View");
 
805
  sMenuText     = QT_TR_NOOP("Rear");
 
806
  sToolTipText  = QT_TR_NOOP("Set to rear view");
 
807
  sWhatsThis    = "Std_ViewXX";
 
808
  sStatusTip    = QT_TR_NOOP("Set to rear view");
 
809
  sPixmap       = "view-rear";
 
810
  iAccel        = Qt::Key_4;
 
811
}
 
812
 
 
813
void StdCmdViewRear::activated(int iMsg)
 
814
{
 
815
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewRear()");
 
816
}
 
817
 
 
818
//===========================================================================
 
819
// Std_ViewRight
 
820
//===========================================================================
 
821
DEF_3DV_CMD(StdCmdViewRight);
 
822
 
 
823
StdCmdViewRight::StdCmdViewRight()
 
824
  : Command("Std_ViewRight")
 
825
{
 
826
  sGroup        = QT_TR_NOOP("Standard-View");
 
827
  sMenuText     = QT_TR_NOOP("Right");
 
828
  sToolTipText  = QT_TR_NOOP("Set to right view");
 
829
  sWhatsThis    = "Std_ViewXX";
 
830
  sStatusTip    = QT_TR_NOOP("Set to right view");
 
831
  sPixmap       = "view-right";
 
832
  iAccel        = Qt::Key_3;
 
833
}
 
834
 
 
835
void StdCmdViewRight::activated(int iMsg)
 
836
{
 
837
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewRight()");
 
838
}
 
839
 
 
840
//===========================================================================
 
841
// Std_ViewTop
 
842
//===========================================================================
 
843
DEF_3DV_CMD(StdCmdViewTop);
 
844
 
 
845
StdCmdViewTop::StdCmdViewTop()
 
846
  : Command("Std_ViewTop")
 
847
{
 
848
  sGroup        = QT_TR_NOOP("Standard-View");
 
849
  sMenuText     = QT_TR_NOOP("Top");
 
850
  sToolTipText  = QT_TR_NOOP("Set to top view");
 
851
  sWhatsThis    = "Std_ViewXX";
 
852
  sStatusTip    = QT_TR_NOOP("Set to top view");
 
853
  sPixmap       = "view-top";
 
854
  iAccel        = Qt::Key_2;
 
855
}
 
856
 
 
857
void StdCmdViewTop::activated(int iMsg)
 
858
{
 
859
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewTop()");
 
860
}
 
861
 
 
862
//===========================================================================
 
863
// Std_ViewAxo
 
864
//===========================================================================
 
865
DEF_3DV_CMD(StdCmdViewAxo);
 
866
 
 
867
StdCmdViewAxo::StdCmdViewAxo()
 
868
  : Command("Std_ViewAxo")
 
869
{
 
870
  sGroup      = QT_TR_NOOP("Standard-View");
 
871
  sMenuText   = QT_TR_NOOP("Axometric");
 
872
  sToolTipText= QT_TR_NOOP("Set to axometric view");
 
873
  sWhatsThis  = "Std_ViewXX";
 
874
  sStatusTip  = QT_TR_NOOP("Set to axometric view");
 
875
  sPixmap     = "view-axometric";
 
876
  iAccel      = Qt::Key_0;
 
877
}
 
878
 
 
879
void StdCmdViewAxo::activated(int iMsg)
 
880
{
 
881
  doCommand(Command::Gui,"Gui.activeDocument().activeView().viewAxometric()");
 
882
}
 
883
 
 
884
//===========================================================================
 
885
// Std_ViewFitAll
 
886
//===========================================================================
 
887
DEF_STD_CMD_A(StdCmdViewFitAll);
 
888
 
 
889
StdCmdViewFitAll::StdCmdViewFitAll()
 
890
  : Command("Std_ViewFitAll")
 
891
{
 
892
  sGroup        = QT_TR_NOOP("Standard-View");
 
893
  sMenuText     = QT_TR_NOOP("Fit all");
 
894
  sToolTipText  = QT_TR_NOOP("Fits the whole content on the screen");
 
895
  sWhatsThis    = "Std_ViewFitAll";
 
896
  sStatusTip    = QT_TR_NOOP("Fits the whole content on the screen");
 
897
  sPixmap       = "view-zoom-all";
 
898
  iAccel        = 0;
 
899
}
 
900
 
 
901
void StdCmdViewFitAll::activated(int iMsg)
 
902
{
 
903
  //doCommand(Command::Gui,"Gui.activeDocument().activeView().fitAll()");
 
904
   doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"ViewFit\")");
 
905
}
 
906
 
 
907
bool StdCmdViewFitAll::isActive(void)
 
908
{
 
909
  //return isViewOfType(Gui::View3DInventor::getClassTypeId());
 
910
  return getGuiApplication()->sendHasMsgToActiveView("ViewFit");
 
911
}
 
912
 
 
913
//===========================================================================
 
914
// Std_ViewFitSelection
 
915
//===========================================================================
 
916
DEF_STD_CMD_A(StdCmdViewFitSelection);
 
917
 
 
918
StdCmdViewFitSelection::StdCmdViewFitSelection()
 
919
  : Command("Std_ViewFitSelection")
 
920
{
 
921
    sGroup        = QT_TR_NOOP("Standard-View");
 
922
    sMenuText     = QT_TR_NOOP("Fit selection");
 
923
    sToolTipText  = QT_TR_NOOP("Fits the selected content on the screen");
 
924
    sWhatsThis    = "Std_ViewFitSelection";
 
925
    sStatusTip    = QT_TR_NOOP("Fits the selected content on the screen");
 
926
#if QT_VERSION >= 0x040200
 
927
    sPixmap       = "view-zoom-selection";
 
928
#endif
 
929
    iAccel        = 0;
 
930
}
 
931
 
 
932
void StdCmdViewFitSelection::activated(int iMsg)
 
933
{
 
934
    //doCommand(Command::Gui,"Gui.activeDocument().activeView().fitAll()");
 
935
    doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"ViewSelection\")");
 
936
}
 
937
 
 
938
bool StdCmdViewFitSelection::isActive(void)
 
939
{
 
940
  //return isViewOfType(Gui::View3DInventor::getClassTypeId());
 
941
  return getGuiApplication()->sendHasMsgToActiveView("ViewSelection");
 
942
}
 
943
 
 
944
//===========================================================================
 
945
// Std_ViewDockUndockFullscreen
 
946
//===========================================================================
 
947
DEF_STD_CMD_AC(StdViewDockUndockFullscreen);
 
948
 
 
949
StdViewDockUndockFullscreen::StdViewDockUndockFullscreen()
 
950
  : Command("Std_ViewDockUndockFullscreen")
 
951
{
 
952
  sGroup      = QT_TR_NOOP("Standard-View");
 
953
  sMenuText   = QT_TR_NOOP("Display mode");
 
954
  sToolTipText= QT_TR_NOOP("Display the active view either in fullscreen, in undocked or docked mode");
 
955
  sWhatsThis  = "Std_ViewDockUndockFullscreen";
 
956
  sStatusTip  = QT_TR_NOOP("Display the active view either in fullscreen, in undocked or docked mode");
 
957
}
 
958
 
 
959
Action * StdViewDockUndockFullscreen::createAction(void)
 
960
{
 
961
  ActionGroup* pcAction = new ActionGroup(this, getMainWindow());
 
962
  pcAction->setDropDownMenu(true);
 
963
  pcAction->setText(QObject::tr(sMenuText));
 
964
 
 
965
  QAction* docked = pcAction->addAction(QObject::tr(QT_TR_NOOP("Docked")));
 
966
  docked->setToolTip(QObject::tr(sToolTipText));
 
967
  docked->setStatusTip(QObject::tr(sStatusTip));
 
968
  docked->setWhatsThis(QObject::tr(sWhatsThis));
 
969
  docked->setShortcut(Qt::Key_D);
 
970
  docked->setCheckable(true);
 
971
 
 
972
  QAction* undocked = pcAction->addAction(QObject::tr(QT_TR_NOOP("Undocked")));
 
973
  undocked->setToolTip(QObject::tr(sToolTipText));
 
974
  undocked->setStatusTip(QObject::tr(sStatusTip));
 
975
  undocked->setWhatsThis(QObject::tr(sWhatsThis));
 
976
  undocked->setShortcut(Qt::Key_U);
 
977
  undocked->setCheckable(true);
 
978
 
 
979
  QAction* fullscr = pcAction->addAction(QObject::tr(QT_TR_NOOP("Fullscreen")));
 
980
  fullscr->setToolTip(QObject::tr(sToolTipText));
 
981
  fullscr->setStatusTip(QObject::tr(sStatusTip));
 
982
  fullscr->setWhatsThis(QObject::tr(sWhatsThis));
 
983
  fullscr->setShortcut(Qt::Key_F11);
 
984
  fullscr->setCheckable(true);
 
985
  fullscr->setIcon(Gui::BitmapFactory().pixmap("view-fullscreen"));
 
986
 
 
987
  return pcAction;
 
988
}
 
989
 
 
990
void StdViewDockUndockFullscreen::activated(int iMsg)
 
991
{
 
992
  MDIView* view = getMainWindow()->activeWindow();
 
993
  if ( !view ) return; // no active view
 
994
  if ( iMsg == (int)(view->currentViewMode()) ) 
 
995
    return; // nothing to do
 
996
 
 
997
  if (iMsg==0)
 
998
  {
 
999
    view->setCurrentViewMode( MDIView::Child );
 
1000
  }
 
1001
  else if (iMsg==1)
 
1002
  {
 
1003
    view->setCurrentViewMode( MDIView::TopLevel );
 
1004
  }
 
1005
  else if (iMsg==2)
 
1006
  {
 
1007
    view->setCurrentViewMode( MDIView::FullScreen );
 
1008
  }
 
1009
}
 
1010
 
 
1011
bool StdViewDockUndockFullscreen::isActive(void)
 
1012
{
 
1013
  MDIView* view = getMainWindow()->activeWindow();
 
1014
  if ( view )
 
1015
  {
 
1016
    // update the action group if needed
 
1017
    ActionGroup* pActGrp = qobject_cast<ActionGroup*>(_pcAction);
 
1018
    if ( pActGrp )
 
1019
    {
 
1020
      int index = pActGrp->checkedAction();
 
1021
      int mode = (int)(view->currentViewMode());
 
1022
      if ( index != mode )
 
1023
      {
 
1024
        // active window has changed with another view mode
 
1025
        pActGrp->setCheckedAction( mode );
 
1026
      }
 
1027
    }
 
1028
 
 
1029
    return true;
 
1030
  }
 
1031
 
 
1032
  return false;
 
1033
}
 
1034
 
 
1035
//===========================================================================
 
1036
// Std_ViewScreenShot
 
1037
//===========================================================================
 
1038
DEF_STD_CMD_A(StdViewScreenShot);
 
1039
 
 
1040
StdViewScreenShot::StdViewScreenShot()
 
1041
  : Command("Std_ViewScreenShot")
 
1042
{
 
1043
    sGroup      = QT_TR_NOOP("Standard-View");
 
1044
    sMenuText   = QT_TR_NOOP("Save picture...");
 
1045
    sToolTipText= QT_TR_NOOP("Creates a screenshot of the active view");
 
1046
    sWhatsThis  = "Std_ViewScreenShot";
 
1047
    sStatusTip  = QT_TR_NOOP("Creates a screenshot of the active view");
 
1048
    iAccel      = 0;
 
1049
    sPixmap     = "camera-photo";
 
1050
}
 
1051
 
 
1052
void StdViewScreenShot::activated(int iMsg)
 
1053
{
 
1054
    View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
1055
    if (view) {
 
1056
        QStringList formats;
 
1057
        SbViewportRegion vp(view->getViewer()->getViewportRegion());
 
1058
        {
 
1059
            SoFCOffscreenRenderer& rd = SoFCOffscreenRenderer::instance();
 
1060
            formats = rd.getWriteImageFiletypeInfo();
 
1061
        }
 
1062
 
 
1063
        QStringList filter;
 
1064
        QString selFilter;
 
1065
        for (QStringList::Iterator it = formats.begin(); it != formats.end(); ++it) {
 
1066
            filter << QString::fromAscii("%1 %2 (*.%3)").arg((*it).toUpper()).
 
1067
                arg(QObject::tr("files")).arg((*it).toLower());
 
1068
        }
 
1069
 
 
1070
        FileOptionsDialog fd(getMainWindow(), 0);
 
1071
        fd.setFileMode(QFileDialog::AnyFile);
 
1072
        fd.setAcceptMode(QFileDialog::AcceptSave);
 
1073
        fd.setWindowTitle(QObject::tr("Save picture"));
 
1074
        fd.setFilters(filter);
 
1075
 
 
1076
        // create the image options widget
 
1077
        DlgSettingsImageImp* opt = new DlgSettingsImageImp(&fd);
 
1078
        SbVec2s sz = vp.getWindowSize();
 
1079
        opt->setImageSize((int)sz[0], (int)sz[1]);
 
1080
 
 
1081
        fd.setOptionsWidget(FileOptionsDialog::ExtensionRight, opt);
 
1082
        fd.setConfirmOverwrite(true);
 
1083
        opt->onSelectedFilter(fd.selectedFilter());
 
1084
        QObject::connect(&fd, SIGNAL(filterSelected(const QString&)),
 
1085
                         opt, SLOT(onSelectedFilter(const QString&)));
 
1086
 
 
1087
        if (fd.exec() == QDialog::Accepted) {
 
1088
            selFilter = fd.selectedFilter();
 
1089
            QString fn = fd.selectedFiles().front();
 
1090
            // We must convert '\' path separators to '/' before otherwise
 
1091
            // Python would interpret them as escape sequences.
 
1092
            fn.replace(QLatin1Char('\\'), QLatin1Char('/'));
 
1093
 
 
1094
            Gui::WaitCursor wc;
 
1095
 
 
1096
            // get the defined values
 
1097
            int w = opt->imageWidth();
 
1098
            int h = opt->imageHeight();
 
1099
 
 
1100
            // search for the matching format
 
1101
            QString format = formats.front(); // take the first as default
 
1102
            for (QStringList::Iterator it = formats.begin(); it != formats.end(); ++it) {
 
1103
                if (selFilter.startsWith((*it).toUpper())) {
 
1104
                    format = *it;
 
1105
                    break;
 
1106
                }
 
1107
            }
 
1108
 
 
1109
            // which background chosen
 
1110
            const char* background;
 
1111
            switch(opt->backgroundType()){
 
1112
                case 0:  background="Current"; break;
 
1113
                case 1:  background="White"; break;
 
1114
                case 2:  background="Black"; break;
 
1115
                case 3:  background="Transparent"; break;
 
1116
                default: background="Current"; break;
 
1117
            }
 
1118
 
 
1119
            QString comment = opt->comment();
 
1120
            if (!comment.isEmpty()) {
 
1121
                // Replace newline escape sequence trough '\\n' string to build one big string,
 
1122
                // otherwise Python would interpret it as an invalid command. 
 
1123
                // Python does the decoding for us.
 
1124
                QStringList lines = comment.split(QLatin1String("\n"), QString::KeepEmptyParts );
 
1125
                    comment = lines.join(QLatin1String("\\n"));
 
1126
                doCommand(Gui,"Gui.activeDocument().activeView().saveImage('%s',%d,%d,'%s','%s')",
 
1127
                            fn.toUtf8().constData(),w,h,background,comment.toUtf8().constData());
 
1128
            }
 
1129
            else {
 
1130
                doCommand(Gui,"Gui.activeDocument().activeView().saveImage('%s',%d,%d,'%s')",
 
1131
                            fn.toUtf8().constData(),w,h,background);
 
1132
            }
 
1133
        }
 
1134
    }
 
1135
}
 
1136
 
 
1137
bool StdViewScreenShot::isActive(void)
 
1138
{
 
1139
    return isViewOfType(Gui::View3DInventor::getClassTypeId());
 
1140
}
 
1141
 
 
1142
 
 
1143
//===========================================================================
 
1144
// Std_ViewCreate
 
1145
//===========================================================================
 
1146
DEF_STD_CMD_A(StdCmdViewCreate);
 
1147
 
 
1148
StdCmdViewCreate::StdCmdViewCreate()
 
1149
  : Command("Std_ViewCreate")
 
1150
{
 
1151
    sGroup      = QT_TR_NOOP("Standard-View");
 
1152
    sMenuText   = QT_TR_NOOP("Create new view");
 
1153
    sToolTipText= QT_TR_NOOP("Creates a new  view window for the active document");
 
1154
    sWhatsThis  = "Std_ViewCreate";
 
1155
    sStatusTip  = QT_TR_NOOP("Creates a new  view window for the active document");
 
1156
    sPixmap     = "window-new";
 
1157
    iAccel      = 0;
 
1158
}
 
1159
 
 
1160
void StdCmdViewCreate::activated(int iMsg)
 
1161
{
 
1162
  getActiveGuiDocument()->createView("View3DIv");
 
1163
}
 
1164
 
 
1165
bool StdCmdViewCreate::isActive(void)
 
1166
{
 
1167
  return (getActiveGuiDocument()!=NULL);
 
1168
}
 
1169
 
 
1170
//===========================================================================
 
1171
// Std_ViewExample1
 
1172
//===========================================================================
 
1173
DEF_STD_CMD_A(StdCmdViewExample1);
 
1174
 
 
1175
StdCmdViewExample1::StdCmdViewExample1()
 
1176
  : Command("Std_ViewExample1")
 
1177
{
 
1178
  sGroup        = QT_TR_NOOP("Standard-View");
 
1179
  sMenuText     = QT_TR_NOOP("Inventor example #1");
 
1180
  sToolTipText  = QT_TR_NOOP("Shows a 3D texture with manipulator");
 
1181
  sWhatsThis    = "Std_ViewExamples";
 
1182
  sStatusTip    = QT_TR_NOOP("Shows a 3D texture with manipulator");
 
1183
  sPixmap       = "Std_Tool1";
 
1184
  iAccel        = 0;
 
1185
}
 
1186
 
 
1187
void StdCmdViewExample1::activated(int iMsg)
 
1188
{
 
1189
  doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"Example1\")");
 
1190
}
 
1191
 
 
1192
bool StdCmdViewExample1::isActive(void)
 
1193
{
 
1194
  return getGuiApplication()->sendHasMsgToActiveView("Example1");
 
1195
}
 
1196
//===========================================================================
 
1197
// Std_ViewExample2
 
1198
//===========================================================================
 
1199
DEF_STD_CMD_A(StdCmdViewExample2);
 
1200
 
 
1201
StdCmdViewExample2::StdCmdViewExample2()
 
1202
  : Command("Std_ViewExample2")
 
1203
{
 
1204
  sGroup        = QT_TR_NOOP("Standard-View");
 
1205
  sMenuText     = QT_TR_NOOP("Inventor example #2");
 
1206
  sToolTipText  = QT_TR_NOOP("Shows spheres an dragglights");
 
1207
  sWhatsThis    = "Std_ViewExamples";
 
1208
  sStatusTip    = QT_TR_NOOP("Shows spheres an dragglights");
 
1209
  sPixmap       = "Std_Tool2";
 
1210
  iAccel        = 0;
 
1211
}
 
1212
 
 
1213
void StdCmdViewExample2::activated(int iMsg)
 
1214
{
 
1215
  doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"Example2\")");
 
1216
}
 
1217
 
 
1218
bool StdCmdViewExample2::isActive(void)
 
1219
{
 
1220
  return getGuiApplication()->sendHasMsgToActiveView("Example2");
 
1221
}
 
1222
 
 
1223
//===========================================================================
 
1224
// Std_ViewExample3
 
1225
//===========================================================================
 
1226
DEF_STD_CMD_A(StdCmdViewExample3);
 
1227
 
 
1228
StdCmdViewExample3::StdCmdViewExample3()
 
1229
  : Command("Std_ViewExample3")
 
1230
{
 
1231
  sGroup        = QT_TR_NOOP("Standard-View");
 
1232
  sMenuText     = QT_TR_NOOP("Inventor example #3");
 
1233
  sToolTipText  = QT_TR_NOOP("Shows a animated texture");
 
1234
  sWhatsThis    = "Std_ViewExamples";
 
1235
  sStatusTip    = QT_TR_NOOP("Shows a animated texture");
 
1236
  sPixmap       = "Std_Tool3";
 
1237
  iAccel        = 0;
 
1238
}
 
1239
 
 
1240
void StdCmdViewExample3::activated(int iMsg)
 
1241
{
 
1242
  doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"Example3\")");
 
1243
}
 
1244
 
 
1245
bool StdCmdViewExample3::isActive(void)
 
1246
{
 
1247
  return getGuiApplication()->sendHasMsgToActiveView("Example3");
 
1248
}
 
1249
 
 
1250
 
 
1251
//===========================================================================
 
1252
// Std_ViewIvStereoOff
 
1253
//===========================================================================
 
1254
DEF_STD_CMD_A(StdCmdViewIvStereoOff);
 
1255
 
 
1256
StdCmdViewIvStereoOff::StdCmdViewIvStereoOff()
 
1257
  : Command("Std_ViewIvStereoOff")
 
1258
{
 
1259
  sGroup        = QT_TR_NOOP("Standard-View");
 
1260
  sMenuText     = QT_TR_NOOP("Stereo Off");
 
1261
  sToolTipText  = QT_TR_NOOP("Switch stereo viewing off");
 
1262
  sWhatsThis    = "Std_ViewIvStereo";
 
1263
  sStatusTip    = QT_TR_NOOP("Switch stereo viewing off");
 
1264
  sPixmap       = "Std_Tool6";
 
1265
  iAccel        = 0;
 
1266
}
 
1267
 
 
1268
void StdCmdViewIvStereoOff::activated(int iMsg)
 
1269
{
 
1270
  doCommand(Command::Gui,"Gui.activeDocument().activeView().setStereoType(\"None\")");
 
1271
}
 
1272
 
 
1273
bool StdCmdViewIvStereoOff::isActive(void)
 
1274
{
 
1275
  return getGuiApplication()->sendHasMsgToActiveView("SetStereoOff");
 
1276
}
 
1277
 
 
1278
 
 
1279
//===========================================================================
 
1280
// Std_ViewIvStereoRedGreen
 
1281
//===========================================================================
 
1282
DEF_STD_CMD_A(StdCmdViewIvStereoRedGreen);
 
1283
 
 
1284
StdCmdViewIvStereoRedGreen::StdCmdViewIvStereoRedGreen()
 
1285
  : Command("Std_ViewIvStereoRedGreen")
 
1286
{
 
1287
  sGroup        = QT_TR_NOOP("Standard-View");
 
1288
  sMenuText     = QT_TR_NOOP("Stereo red/green");
 
1289
  sToolTipText  = QT_TR_NOOP("Switch stereo viewing to red/green");
 
1290
  sWhatsThis    = "Std_ViewIvStereo";
 
1291
  sStatusTip    = QT_TR_NOOP("Switch stereo viewing to red/green");
 
1292
  sPixmap       = "Std_Tool7";
 
1293
  iAccel        = 0;
 
1294
}
 
1295
 
 
1296
void StdCmdViewIvStereoRedGreen::activated(int iMsg)
 
1297
{
 
1298
  doCommand(Command::Gui,"Gui.activeDocument().activeView().setStereoType(\"Anaglyph\")");
 
1299
}
 
1300
 
 
1301
bool StdCmdViewIvStereoRedGreen::isActive(void)
 
1302
{
 
1303
  return getGuiApplication()->sendHasMsgToActiveView("SetStereoRedGreen");
 
1304
}
 
1305
 
 
1306
//===========================================================================
 
1307
// Std_ViewIvStereoQuadBuff
 
1308
//===========================================================================
 
1309
DEF_STD_CMD_A(StdCmdViewIvStereoQuadBuff);
 
1310
 
 
1311
StdCmdViewIvStereoQuadBuff::StdCmdViewIvStereoQuadBuff()
 
1312
  : Command("Std_ViewIvStereoQuadBuff")
 
1313
{
 
1314
  sGroup        = QT_TR_NOOP("Standard-View");
 
1315
  sMenuText     = QT_TR_NOOP("Stereo quad buffer");
 
1316
  sToolTipText  = QT_TR_NOOP("Switch stereo viewing to quad buffer");
 
1317
  sWhatsThis    = "Std_ViewIvStereo";
 
1318
  sStatusTip    = QT_TR_NOOP("Switch stereo viewing to quad buffer");
 
1319
  sPixmap       = "Std_Tool7";
 
1320
  iAccel        = 0;
 
1321
}
 
1322
 
 
1323
void StdCmdViewIvStereoQuadBuff::activated(int iMsg)
 
1324
{
 
1325
  doCommand(Command::Gui,"Gui.activeDocument().activeView().setStereoType(\"QuadBuffer\")");
 
1326
}
 
1327
 
 
1328
bool StdCmdViewIvStereoQuadBuff::isActive(void)
 
1329
{
 
1330
  return getGuiApplication()->sendHasMsgToActiveView("SetStereoQuadBuff");
 
1331
}
 
1332
 
 
1333
//===========================================================================
 
1334
// Std_ViewIvStereoInterleavedRows
 
1335
//===========================================================================
 
1336
DEF_STD_CMD_A(StdCmdViewIvStereoInterleavedRows);
 
1337
 
 
1338
StdCmdViewIvStereoInterleavedRows::StdCmdViewIvStereoInterleavedRows()
 
1339
  : Command("Std_ViewIvStereoInterleavedRows")
 
1340
{
 
1341
  sGroup        = QT_TR_NOOP("Standard-View");
 
1342
  sMenuText     = QT_TR_NOOP("Stereo Interleaved Rows");
 
1343
  sToolTipText  = QT_TR_NOOP("Switch stereo viewing to Interleaved Rows");
 
1344
  sWhatsThis    = "Std_ViewIvStereo";
 
1345
  sStatusTip    = QT_TR_NOOP("Switch stereo viewing to Interleaved Rows");
 
1346
  sPixmap       = "Std_Tool7";
 
1347
  iAccel        = 0;
 
1348
}
 
1349
 
 
1350
void StdCmdViewIvStereoInterleavedRows::activated(int iMsg)
 
1351
{
 
1352
  doCommand(Command::Gui,"Gui.activeDocument().activeView().setStereoType(\"InterleavedRows\")");
 
1353
}
 
1354
 
 
1355
bool StdCmdViewIvStereoInterleavedRows::isActive(void)
 
1356
{
 
1357
  return getGuiApplication()->sendHasMsgToActiveView("SetStereoInterleavedRows");
 
1358
}
 
1359
 
 
1360
//===========================================================================
 
1361
// Std_ViewIvStereoInterleavedColumns
 
1362
//===========================================================================
 
1363
DEF_STD_CMD_A(StdCmdViewIvStereoInterleavedColumns);
 
1364
 
 
1365
StdCmdViewIvStereoInterleavedColumns::StdCmdViewIvStereoInterleavedColumns()
 
1366
  : Command("Std_ViewIvStereoInterleavedColumns")
 
1367
{
 
1368
  sGroup        = QT_TR_NOOP("Standard-View");
 
1369
  sMenuText     = QT_TR_NOOP("Stereo Interleaved Columns");
 
1370
  sToolTipText  = QT_TR_NOOP("Switch stereo viewing to Interleaved Columns");
 
1371
  sWhatsThis    = "Std_ViewIvStereo";
 
1372
  sStatusTip    = QT_TR_NOOP("Switch stereo viewing to Interleaved Columns");
 
1373
  sPixmap       = "Std_Tool7";
 
1374
  iAccel        = 0;
 
1375
}
 
1376
 
 
1377
void StdCmdViewIvStereoInterleavedColumns::activated(int iMsg)
 
1378
{
 
1379
  doCommand(Command::Gui,"Gui.activeDocument().activeView().setStereoType(\"InterleavedColumns\")");
 
1380
}
 
1381
 
 
1382
bool StdCmdViewIvStereoInterleavedColumns::isActive(void)
 
1383
{
 
1384
  return getGuiApplication()->sendHasMsgToActiveView("SetStereoInterleavedColumns");
 
1385
}
 
1386
 
 
1387
 
 
1388
//===========================================================================
 
1389
// Std_ViewIvIssueCamPos
 
1390
//===========================================================================
 
1391
DEF_STD_CMD_A(StdCmdViewIvIssueCamPos);
 
1392
 
 
1393
StdCmdViewIvIssueCamPos::StdCmdViewIvIssueCamPos()
 
1394
  : Command("Std_ViewIvIssueCamPos")
 
1395
{
 
1396
  sGroup        = QT_TR_NOOP("Standard-View");
 
1397
  sMenuText     = QT_TR_NOOP("Issue camera position");
 
1398
  sToolTipText  = QT_TR_NOOP("Issue the camera position to the console and to a macro, to easily recall this position");
 
1399
  sWhatsThis    = "Std_ViewIvIssueCamPos";
 
1400
  sStatusTip    = QT_TR_NOOP("Issue the camera position to the console and to a macro, to easily recall this position");
 
1401
  sPixmap       = "Std_Tool8";
 
1402
  iAccel        = 0;
 
1403
}
 
1404
 
 
1405
void StdCmdViewIvIssueCamPos::activated(int iMsg)
 
1406
{
 
1407
  std::string Temp,Temp2;
 
1408
  std::string::size_type pos;
 
1409
 
 
1410
  const char* ppReturn=0;
 
1411
  getGuiApplication()->sendMsgToActiveView("GetCamera",&ppReturn);
 
1412
 
 
1413
  // remove the #inventor line...
 
1414
  Temp2 = ppReturn;
 
1415
  pos = Temp2.find_first_of("\n");
 
1416
  Temp2.erase(0,pos);
 
1417
 
 
1418
  // remove all returns
 
1419
  while((pos=Temp2.find('\n')) != std::string::npos)
 
1420
    Temp2.replace(pos,1," ");
 
1421
 
 
1422
  // build up the command string
 
1423
  Temp += "Gui.SendMsgToActiveView(\"SetCamera ";
 
1424
  Temp += Temp2;
 
1425
  Temp += "\")";
 
1426
 
 
1427
  Base::Console().Message("%s\n",Temp2.c_str());
 
1428
  getGuiApplication()->macroManager()->addLine(MacroManager::Gui,Temp.c_str());
 
1429
}
 
1430
 
 
1431
bool StdCmdViewIvIssueCamPos::isActive(void)
 
1432
{
 
1433
  return getGuiApplication()->sendHasMsgToActiveView("GetCamera");
 
1434
}
 
1435
 
 
1436
 
 
1437
//===========================================================================
 
1438
// Std_ViewZoomIn
 
1439
//===========================================================================
 
1440
DEF_STD_CMD_A(StdViewZoomIn);
 
1441
 
 
1442
StdViewZoomIn::StdViewZoomIn()
 
1443
  : Command("Std_ViewZoomIn")
 
1444
{
 
1445
    sGroup        = QT_TR_NOOP("Standard-View");
 
1446
    sMenuText     = QT_TR_NOOP("Zoom In");
 
1447
    sToolTipText  = QT_TR_NOOP("Zoom In");
 
1448
    sWhatsThis    = "Std_ViewZoom";
 
1449
    sStatusTip    = QT_TR_NOOP("Zoom In");
 
1450
#if QT_VERSION >= 0x040200
 
1451
    sPixmap       = "view-zoom-in";
 
1452
#endif
 
1453
    iAccel        = Qt::Key_Plus;
 
1454
}
 
1455
 
 
1456
void StdViewZoomIn::activated(int iMsg)
 
1457
{
 
1458
    View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
1459
    if ( view ) {
 
1460
        View3DInventorViewer* viewer = view->getViewer();
 
1461
 
 
1462
        // send an event to the GL widget to use the internal View3DInventorViewer::zoom() method
 
1463
        // do only one step to zoom in 
 
1464
        SoMouseButtonEvent e;
 
1465
        e.setButton(SoMouseButtonEvent::BUTTON5);
 
1466
        e.setState(SoMouseButtonEvent::DOWN);
 
1467
        viewer->sendSoEvent(&e);
 
1468
    }
 
1469
}
 
1470
 
 
1471
bool StdViewZoomIn::isActive(void)
 
1472
{
 
1473
    return (qobject_cast<View3DInventor*>(getMainWindow()->activeWindow()));
 
1474
}
 
1475
 
 
1476
//===========================================================================
 
1477
// Std_ViewZoomOut
 
1478
//===========================================================================
 
1479
DEF_STD_CMD_A(StdViewZoomOut);
 
1480
 
 
1481
StdViewZoomOut::StdViewZoomOut()
 
1482
  : Command("Std_ViewZoomOut")
 
1483
{
 
1484
    sGroup        = QT_TR_NOOP("Standard-View");
 
1485
    sMenuText     = QT_TR_NOOP("Zoom Out");
 
1486
    sToolTipText  = QT_TR_NOOP("Zoom Out");
 
1487
    sWhatsThis    = "Std_ViewZoom";
 
1488
    sStatusTip    = QT_TR_NOOP("Zoom Out");
 
1489
#if QT_VERSION >= 0x040200
 
1490
    sPixmap       = "view-zoom-out";
 
1491
#endif
 
1492
    iAccel        = Qt::Key_Minus;
 
1493
}
 
1494
 
 
1495
void StdViewZoomOut::activated(int iMsg)
 
1496
{
 
1497
    View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
1498
    if ( view ) {
 
1499
        View3DInventorViewer* viewer = view->getViewer();
 
1500
        // send an event to the GL widget to use the internal View3DInventorViewer::zoom() method
 
1501
        // do only one step to zoom out 
 
1502
        SoMouseButtonEvent e;
 
1503
        e.setButton(SoMouseButtonEvent::BUTTON4);
 
1504
        e.setState(SoMouseButtonEvent::DOWN);
 
1505
        viewer->sendSoEvent(&e);
 
1506
    }
 
1507
}
 
1508
 
 
1509
bool StdViewZoomOut::isActive(void)
 
1510
{
 
1511
    return (qobject_cast<View3DInventor*>(getMainWindow()->activeWindow()));
 
1512
}
 
1513
 
 
1514
//===========================================================================
 
1515
// Std_ViewBoxZoom
 
1516
//===========================================================================
 
1517
DEF_3DV_CMD(StdViewBoxZoom);
 
1518
 
 
1519
StdViewBoxZoom::StdViewBoxZoom()
 
1520
  : Command("Std_ViewBoxZoom")
 
1521
{
 
1522
    sGroup        = QT_TR_NOOP("Standard-View");
 
1523
    sMenuText     = QT_TR_NOOP("Box zoom");
 
1524
    sToolTipText  = QT_TR_NOOP("Box zoom");
 
1525
    sWhatsThis    = "Std_ViewBoxZoom";
 
1526
    sStatusTip    = QT_TR_NOOP("Box zoom");
 
1527
#if QT_VERSION >= 0x040200
 
1528
    sPixmap       = "view-zoom-border";
 
1529
#endif
 
1530
    iAccel        = Qt::CTRL+Qt::Key_B;
 
1531
}
 
1532
 
 
1533
void StdViewBoxZoom::activated(int iMsg)
 
1534
{
 
1535
    View3DInventor* view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
1536
    if ( view ) {
 
1537
        View3DInventorViewer* viewer = view->getViewer();
 
1538
        if (!viewer->isPicking())
 
1539
            viewer->startPicking(View3DInventorViewer::BoxZoom);
 
1540
    }
 
1541
}
 
1542
 
 
1543
//===========================================================================
 
1544
// Std_TreeSelection
 
1545
//===========================================================================
 
1546
 
 
1547
DEF_STD_CMD(StdCmdTreeSelection);
 
1548
 
 
1549
StdCmdTreeSelection::StdCmdTreeSelection()
 
1550
  : Command("Std_TreeSelection")
 
1551
{
 
1552
    sGroup        = QT_TR_NOOP("View");
 
1553
    sMenuText     = QT_TR_NOOP("Go to selection");
 
1554
    sToolTipText  = QT_TR_NOOP("Scroll to first selected item");
 
1555
    sWhatsThis    = "Std_TreeSelection";
 
1556
    sStatusTip    = QT_TR_NOOP("Scroll to first selected item");
 
1557
    iAccel        = 0;
 
1558
}
 
1559
 
 
1560
void StdCmdTreeSelection::activated(int iMsg)
 
1561
{
 
1562
    QList<TreeWidget*> tree = Gui::getMainWindow()->findChildren<TreeWidget*>();
 
1563
    for (QList<TreeWidget*>::iterator it = tree.begin(); it != tree.end(); ++it) {
 
1564
        Gui::Document* doc = Gui::Application::Instance->activeDocument();
 
1565
        (*it)->scrollItemToTop(doc);
 
1566
    }
 
1567
}
 
1568
 
 
1569
//===========================================================================
 
1570
// Std_MeasureDistance
 
1571
//===========================================================================
 
1572
 
 
1573
DEF_STD_CMD_A(StdCmdMeasureDistance);
 
1574
 
 
1575
StdCmdMeasureDistance::StdCmdMeasureDistance()
 
1576
  : Command("Std_MeasureDistance")
 
1577
{
 
1578
    sGroup        = QT_TR_NOOP("View");
 
1579
    sMenuText     = QT_TR_NOOP("Measure distance");
 
1580
    sToolTipText  = QT_TR_NOOP("Measure distance");
 
1581
    sWhatsThis    = "Std_MeasureDistance";
 
1582
    sStatusTip    = QT_TR_NOOP("Measure distance");
 
1583
    iAccel        = 0;
 
1584
}
 
1585
 
 
1586
void StdCmdMeasureDistance::activated(int iMsg)
 
1587
{
 
1588
    Gui::Document* doc = Gui::Application::Instance->activeDocument();
 
1589
    Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
 
1590
    if (view) {
 
1591
        App::DocumentObject* obj = doc->getDocument()->addObject(App::MeasureDistance::getClassTypeId().getName(),"Distance");
 
1592
        Gui::View3DInventorViewer* viewer = view->getViewer();
 
1593
        viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), ViewProviderMeasureDistance::measureDistanceCallback, obj);
 
1594
     }
 
1595
}
 
1596
 
 
1597
bool StdCmdMeasureDistance::isActive(void)
 
1598
{
 
1599
    App::Document* doc = App::GetApplication().getActiveDocument();
 
1600
    if (doc && doc->countObjectsOfType(App::GeoFeature::getClassTypeId()) > 0)
 
1601
        return true;
 
1602
    return false;
 
1603
}
 
1604
 
 
1605
//===========================================================================
 
1606
// Std_SceneInspector
 
1607
//===========================================================================
 
1608
 
 
1609
DEF_3DV_CMD(StdCmdSceneInspector);
 
1610
 
 
1611
StdCmdSceneInspector::StdCmdSceneInspector()
 
1612
  : Command("Std_SceneInspector")
 
1613
{
 
1614
    // seting the
 
1615
    sGroup        = QT_TR_NOOP("Tools");
 
1616
    sMenuText     = QT_TR_NOOP("Scene inspector...");
 
1617
    sToolTipText  = QT_TR_NOOP("Scene inspector");
 
1618
    sWhatsThis    = "Std_SceneInspector";
 
1619
    sStatusTip    = QT_TR_NOOP("Scene inspector");
 
1620
}
 
1621
 
 
1622
void StdCmdSceneInspector::activated(int iMsg)
 
1623
{
 
1624
    View3DInventor* child = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
 
1625
    if (child) {
 
1626
        View3DInventorViewer* viewer = child->getViewer();
 
1627
        Gui::Dialog::DlgInspector dlg(getMainWindow());
 
1628
        dlg.setNode(viewer->getSceneGraph());
 
1629
        dlg.exec();
 
1630
    }
 
1631
}
 
1632
 
 
1633
 
 
1634
//===========================================================================
 
1635
// Instanciation
 
1636
//===========================================================================
 
1637
 
 
1638
 
 
1639
namespace Gui {
 
1640
 
 
1641
void CreateViewStdCommands(void)
 
1642
{
 
1643
    CommandManager &rcCmdMgr = Application::Instance->commandManager();
 
1644
 
 
1645
    // views
 
1646
    rcCmdMgr.addCommand(new StdCmdViewBottom());
 
1647
    rcCmdMgr.addCommand(new StdCmdViewFront());
 
1648
    rcCmdMgr.addCommand(new StdCmdViewLeft());
 
1649
    rcCmdMgr.addCommand(new StdCmdViewRear());
 
1650
    rcCmdMgr.addCommand(new StdCmdViewRight());
 
1651
    rcCmdMgr.addCommand(new StdCmdViewTop());
 
1652
    rcCmdMgr.addCommand(new StdCmdViewAxo());
 
1653
    rcCmdMgr.addCommand(new StdCmdViewFitAll());
 
1654
    rcCmdMgr.addCommand(new StdCmdViewFitSelection());
 
1655
 
 
1656
    rcCmdMgr.addCommand(new StdCmdViewExample1());
 
1657
    rcCmdMgr.addCommand(new StdCmdViewExample2());
 
1658
    rcCmdMgr.addCommand(new StdCmdViewExample3());
 
1659
 
 
1660
    rcCmdMgr.addCommand(new StdCmdViewIvStereoQuadBuff());
 
1661
    rcCmdMgr.addCommand(new StdCmdViewIvStereoRedGreen());
 
1662
    rcCmdMgr.addCommand(new StdCmdViewIvStereoInterleavedColumns());
 
1663
    rcCmdMgr.addCommand(new StdCmdViewIvStereoInterleavedRows());
 
1664
    rcCmdMgr.addCommand(new StdCmdViewIvStereoOff());
 
1665
 
 
1666
    rcCmdMgr.addCommand(new StdCmdViewIvIssueCamPos());
 
1667
 
 
1668
    rcCmdMgr.addCommand(new StdCmdViewCreate());
 
1669
    rcCmdMgr.addCommand(new StdViewScreenShot());
 
1670
 
 
1671
    rcCmdMgr.addCommand(new StdViewDockUndockFullscreen());
 
1672
    rcCmdMgr.addCommand(new StdCmdSetAppearance());
 
1673
    rcCmdMgr.addCommand(new StdCmdToggleVisibility());
 
1674
    rcCmdMgr.addCommand(new StdCmdShowSelection());
 
1675
    rcCmdMgr.addCommand(new StdCmdHideSelection());
 
1676
    rcCmdMgr.addCommand(new StdCmdToggleObjects());
 
1677
    rcCmdMgr.addCommand(new StdCmdShowObjects());
 
1678
    rcCmdMgr.addCommand(new StdCmdHideObjects());
 
1679
    rcCmdMgr.addCommand(new StdOrthographicCamera());
 
1680
    rcCmdMgr.addCommand(new StdPerspectiveCamera());
 
1681
    rcCmdMgr.addCommand(new StdCmdToggleClipPlane());
 
1682
    rcCmdMgr.addCommand(new StdCmdFreezeViews());
 
1683
    rcCmdMgr.addCommand(new StdViewZoomIn());
 
1684
    rcCmdMgr.addCommand(new StdViewZoomOut());
 
1685
    rcCmdMgr.addCommand(new StdViewBoxZoom());
 
1686
    rcCmdMgr.addCommand(new StdCmdTreeSelection());
 
1687
    rcCmdMgr.addCommand(new StdCmdMeasureDistance());
 
1688
    rcCmdMgr.addCommand(new StdCmdSceneInspector());
 
1689
}
 
1690
 
 
1691
} // namespace Gui
 
1692