1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#if !defined _WIN32
#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
#endif
#include <inspector/View_Window.hxx>
#include <inspector/View_Displayer.hxx>
#include <inspector/View_DisplayPreview.hxx>
#include <inspector/View_PreviewParameters.hxx>
#include <inspector/View_ToolBar.hxx>
#include <inspector/View_Viewer.hxx>
#include <inspector/View_Widget.hxx>
#include <V3d.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QComboBox>
#include <QDockWidget>
#include <QGridLayout>
#include <QMenu>
#include <QToolBar>
#include <Standard_WarningsRestore.hxx>
const int DEFAULT_SPACING = 3;
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
View_Window::View_Window(QWidget* theParent,
const Handle(AIS_InteractiveContext)& theContext,
const bool isUseKeepView,
const bool isFitAllActive)
: QWidget(theParent)
{
QGridLayout* aViewLayout = new QGridLayout(this);
aViewLayout->setContentsMargins(0, 0, 0, 0);
aViewLayout->setSpacing(DEFAULT_SPACING);
myView = new View_Widget(this, theContext, isFitAllActive);
myViewToolBar = new View_ToolBar(this, isUseKeepView);
aViewLayout->addWidget(myViewToolBar->GetControl(), 0, 0, 1, 2);
connect(myViewToolBar, SIGNAL(contextChanged()), this, SLOT(onViewSelectorActivated()));
connect(myViewToolBar, SIGNAL(actionClicked(int)), this, SLOT(onToolBarActionClicked(int)));
connect(myView,
SIGNAL(checkedStateChanged(int, bool)),
this,
SLOT(onCheckedStateChanged(int, bool)));
myView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(myView,
SIGNAL(customContextMenuRequested(const QPoint&)),
this,
SLOT(onViewContextMenuRequested(const QPoint&)));
myActionsToolBar = new QToolBar(this);
myActionsToolBar->layout()->setContentsMargins(0, 0, 0, 0);
myActionsToolBar->setOrientation(Qt::Vertical);
myActionsToolBar->addWidget(myView->GetWidget(View_ViewActionType_FitAllId));
myActionsToolBar->addAction(myView->ViewAction(View_ViewActionType_DisplayModeId));
aViewLayout->addWidget(myActionsToolBar, 1, 0);
aViewLayout->addWidget(myView, 1, 1);
aViewLayout->setRowStretch(1, 1);
Handle(AIS_InteractiveContext) aContext = myView->GetViewer()->GetContext();
myViewToolBar->SetContext(View_ContextType_Own, aContext);
myDisplayer = new View_Displayer();
if (!isUseKeepView)
myDisplayer->KeepPresentations(true);
myDisplayer->SetFitAllActive(isFitAllActive);
connect(myView, SIGNAL(displayModeClicked()), this, SLOT(onDisplayModeChanged()));
onViewSelectorActivated();
}
// =======================================================================
// function : SetContext
// purpose :
// =======================================================================
void View_Window::SetContext(View_ContextType /*theType*/,
const Handle(AIS_InteractiveContext)& theContext)
{
ViewToolBar()->SetContext(View_ContextType_External, theContext);
}
// =======================================================================
// function : SetPredefinedSize
// purpose :
// =======================================================================
void View_Window::SetPredefinedSize(int theDefaultWidth, int theDefaultHeight)
{
myView->SetPredefinedSize(theDefaultWidth, theDefaultHeight);
}
// =======================================================================
// function : SetInitProj
// purpose :
// =======================================================================
void View_Window::SetInitProj(const Standard_Real theVx,
const Standard_Real theVy,
const Standard_Real theVz)
{
myView->SetInitProj(theVx, theVy, theVz);
}
// =======================================================================
// function : View
// purpose :
// =======================================================================
Handle(V3d_View) View_Window::View() const
{
return myView->GetViewer()->GetView();
}
// =======================================================================
// function : SaveState
// purpose :
// =======================================================================
void View_Window::SaveState(View_Window* theView,
QMap<QString, QString>& theItems,
const QString& thePrefix)
{
QStringList aCameraDirection;
Standard_Real aVX, aVY, aVZ;
Handle(V3d_View) aView = theView->View();
if (aView.IsNull())
return;
aView->Proj(aVX, aVY, aVZ);
aCameraDirection << QString::number(aVX) << QString::number(aVY) << QString::number(aVZ);
theItems[thePrefix + "view_camera_direction"] = aCameraDirection.join(",");
View_PreviewParameters::SaveState(theView->Displayer()->DisplayPreview()->GetPreviewParameters(),
theItems,
"preview_parameters_");
View_ToolBar::SaveState(theView->ViewToolBar(), theItems, "view_toolbar_");
View_Widget::SaveState(theView->ViewWidget(), theItems, "view_widget_");
}
// =======================================================================
// function : RestoreState
// purpose :
// =======================================================================
bool View_Window::RestoreState(View_Window* theView,
const QString& theKey,
const QString& theValue,
const QString& thePrefix)
{
if (theKey == thePrefix + "view_camera_direction")
{
QStringList aValues = theValue.split(",");
if (aValues.size() == 3)
{
Standard_Real aVX = aValues.at(0).toDouble();
Standard_Real aVY = aValues.at(1).toDouble();
Standard_Real aVZ = aValues.at(2).toDouble();
theView->SetInitProj(aVX, aVY, aVZ);
}
return true;
}
else if (View_PreviewParameters::RestoreState(
theView->Displayer()->DisplayPreview()->GetPreviewParameters(),
theKey,
theValue,
"preview_parameters_"))
{
return true;
}
else if (View_ToolBar::RestoreState(theView->ViewToolBar(), theKey, theValue, "view_toolbar_"))
{
return true;
}
else if (View_Widget::RestoreState(theView->ViewWidget(), theKey, theValue, "view_widget_"))
{
// display mode is restored
View_Displayer* aDisplayer = theView->Displayer();
if (theView->ViewWidget()->DisplayMode() != aDisplayer->DisplayMode())
aDisplayer->SetDisplayMode(theView->ViewWidget()->DisplayMode());
bool toFitAll = theView->ViewWidget()->IsActionChecked(View_ViewActionType_FitAllId);
if (toFitAll != aDisplayer->IsFitAllActive())
aDisplayer->SetFitAllActive(toFitAll);
return true;
}
return false;
}
// =======================================================================
// function : onViewSelectorActivated
// purpose :
// =======================================================================
void View_Window::onViewSelectorActivated()
{
View_ContextType aType = myViewToolBar->CurrentContextType();
bool isViewEnabled = aType == View_ContextType_Own;
myView->SetEnabledView(isViewEnabled);
Handle(AIS_InteractiveContext) aContext = myViewToolBar->CurrentContext();
myDisplayer->EraseAllPresentations(true);
emit eraseAllPerformed();
myDisplayer->SetContext(aContext);
}
// =======================================================================
// function : onToolBarActionClicked
// purpose :
// =======================================================================
void View_Window::onToolBarActionClicked(const int theActionId)
{
switch (theActionId)
{
case View_ToolActionType_Trihedron: {
myDisplayer->DisplayDefaultTrihedron(myViewToolBar->IsActionChecked(theActionId),
Standard_True);
break;
}
case View_ToolActionType_ViewCube: {
myDisplayer->DisplayViewCube(myViewToolBar->IsActionChecked(theActionId), Standard_True);
break;
}
case View_ToolActionType_KeepViewId: {
myDisplayer->KeepPresentations(myViewToolBar->IsActionChecked(theActionId));
break;
}
case View_ToolActionType_KeepViewOffId: {
myDisplayer->KeepPresentations(!myViewToolBar->IsActionChecked(theActionId));
break;
}
case View_ToolActionType_ClearViewId: {
myDisplayer->EraseAllPresentations(true);
emit eraseAllPerformed();
break;
}
default:
break;
}
}
// =======================================================================
// function : onCheckedStateChanged
// purpose :
// =======================================================================
void View_Window::onCheckedStateChanged(int theActionId, bool theState)
{
if (theActionId == View_ViewActionType_FitAllId)
myDisplayer->SetFitAllActive(theState);
}
// =======================================================================
// function : onViewContextMenuRequested
// purpose :
// =======================================================================
void View_Window::onViewContextMenuRequested(const QPoint& thePosition)
{
QMenu* aMenu = new QMenu(this);
QMenu* anOrientationSubMenu = aMenu->addMenu("Set View Orientation");
for (int i = 0; i < (int)V3d_XnegYnegZneg; i++)
{
V3d_TypeOfOrientation anOrientationType = (V3d_TypeOfOrientation)i;
QAction* anAction = new QAction(V3d::TypeOfOrientationToString(anOrientationType), this);
QObject::connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onSetOrientation()));
anOrientationSubMenu->addAction(anAction);
}
aMenu->addMenu(anOrientationSubMenu);
QPoint aPoint = myView->mapToGlobal(thePosition);
aMenu->exec(aPoint);
}
// =======================================================================
// function : onSetOrientation
// purpose :
// =======================================================================
void View_Window::onSetOrientation()
{
QAction* anAction = (QAction*)(sender());
TCollection_AsciiString anOrientationStr(anAction->text().toStdString().c_str());
V3d_TypeOfOrientation anOrientationType;
if (!V3d::TypeOfOrientationFromString(anOrientationStr.ToCString(), anOrientationType))
return;
Handle(V3d_View) aView = myView->GetViewer()->GetView();
if (aView.IsNull())
return;
aView->SetProj(anOrientationType);
aView->FitAll();
aView->Redraw();
}
// =======================================================================
// function : onDisplayModeChanged
// purpose :
// =======================================================================
void View_Window::onDisplayModeChanged()
{
int aDisplayMode = myView->DisplayMode();
for (NCollection_DataMap<View_PresentationType,
NCollection_Shared<AIS_ListOfInteractive>>::Iterator
anIterator(myDisplayer->GetDisplayed());
anIterator.More();
anIterator.Next())
myDisplayer->SetDisplayMode(aDisplayMode, anIterator.Key(), false);
myDisplayer->UpdateViewer();
}
|