1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0029674: Improvements in Inspector tool

- preferences for dock windows geometry, tree view columns and current view projection;
- ViewControl package for common functionality between plugins;
- processing Location and Orientation for external TopoDS_Shape object
- 'F5' key to update content of each plugin
- visibility column in tree view (used now only in ShapeView)
- properties child item for context (presents tree of current Filters of context)
This commit is contained in:
nds
2018-03-23 16:08:11 +03:00
committed by bugmaster
parent 6dfdbb7ab8
commit 6822a3bef1
135 changed files with 4187 additions and 1603 deletions

View File

@@ -6,6 +6,9 @@ View_PresentationType.hxx
View_ToolActionType.hxx
View_ToolBar.cxx
View_ToolBar.hxx
View_ToolButton.hxx
View_Tools.cxx
View_Tools.hxx
View_ViewActionType.hxx
View_Viewer.cxx
View_Viewer.hxx

View File

@@ -18,6 +18,9 @@
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Trihedron.hxx>
#include <Prs3d_PointAspect.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <inspector/View_Viewer.hxx>
@@ -28,7 +31,7 @@
// purpose :
// =======================================================================
View_Displayer::View_Displayer()
: myIsKeepPresentations (false), myDisplayMode (-1)
: myIsKeepPresentations (false), myFitAllActive (false), myDisplayMode (-1)
{
}
@@ -107,21 +110,35 @@ void View_Displayer::DisplayPresentation (const Handle(Standard_Transient)& theP
aDisplayed.Append (aPresentation);
}
if (!myIsKeepPresentations)
{
Handle(V3d_View) aView = GetView();
if (!aView.IsNull())
{
aView->FitAll();
aView->Redraw();
}
}
if (!myIsKeepPresentations || myFitAllActive)
fitAllView();
myDisplayed.Bind (theType, aDisplayed);
if (theToUpdateViewer)
UpdateViewer();
}
// =======================================================================
// function : RedisplayPresentation
// purpose :
// =======================================================================
void View_Displayer::RedisplayPresentation (const Handle(Standard_Transient)& thePresentation,
const bool theToUpdateViewer)
{
Handle(AIS_InteractiveObject) aPresentation = Handle(AIS_InteractiveObject)::DownCast (thePresentation);
if (aPresentation.IsNull() || aPresentation->GetContext().IsNull())
return;
GetContext()->Redisplay (aPresentation, false);
if (myFitAllActive)
fitAllView();
if (theToUpdateViewer)
UpdateViewer();
}
// =======================================================================
// function : EraseAllPresentations
// purpose :
@@ -149,12 +166,80 @@ void View_Displayer::ErasePresentations (const View_PresentationType theType, co
DisplayedPresentations (aDisplayed, theType);
for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next())
{
if (aDisplayedIt.Value()->IsKind(STANDARD_TYPE (AIS_Trihedron)))
continue;
GetContext()->Remove (aDisplayedIt.Value(), Standard_False);
}
aDisplayed.Clear();
myDisplayed.Bind (theType, aDisplayed);
if (theToUpdateViewer)
UpdateViewer();
}
// =======================================================================
// function : ErasePresentation
// purpose :
// =======================================================================
void View_Displayer::ErasePresentation (const Handle(Standard_Transient)& thePresentation,
const View_PresentationType theType,
const bool theToUpdateViewer)
{
if (GetContext().IsNull())
return;
Handle(AIS_InteractiveObject) aPresentation = Handle(AIS_InteractiveObject)::DownCast (thePresentation);
if (aPresentation.IsNull())
return;
GetContext()->Remove (aPresentation, Standard_False);
NCollection_Shared<AIS_ListOfInteractive> aDisplayed;
DisplayedPresentations (aDisplayed, theType);
aDisplayed.Remove (aPresentation);
myDisplayed.Bind (theType, aDisplayed);
if (myFitAllActive)
fitAllView();
if (theToUpdateViewer)
UpdateViewer();
}
// =======================================================================
// function : SetVisible
// purpose :
// =======================================================================
void View_Displayer::SetVisible (const TopoDS_Shape& theShape, const bool theState, const View_PresentationType theType)
{
if (theShape.IsNull())
return;
if (theState)
DisplayPresentation (CreatePresentation (theShape), View_PresentationType_Main, Standard_False);
else
{
Handle(AIS_InteractiveObject) aPresentation = FindPresentation (theShape, theType);
if (!aPresentation.IsNull())
ErasePresentation (aPresentation, theType, Standard_False);
}
UpdateViewer();
}
// =======================================================================
// function : IsVisible
// purpose :
// =======================================================================
bool View_Displayer::IsVisible (const TopoDS_Shape& theShape, const View_PresentationType theType) const
{
Handle(AIS_InteractiveObject) aPresentation = FindPresentation (theShape, theType);
return !aPresentation.IsNull();
}
// =======================================================================
// function : UpdateViewer
// purpose :
@@ -181,7 +266,7 @@ void View_Displayer::SetAttributeColor (const Quantity_Color& theColor, const Vi
// purpose :
// =======================================================================
void View_Displayer::DisplayedPresentations (NCollection_Shared<AIS_ListOfInteractive>& thePresentations,
const View_PresentationType theType)
const View_PresentationType theType) const
{
myDisplayed.Find (theType, thePresentations);
}
@@ -205,3 +290,53 @@ Handle(V3d_View) View_Displayer::GetView() const
}
return aView;
}
// =======================================================================
// function : FindPresentation
// purpose :
// =======================================================================
Handle(AIS_InteractiveObject) View_Displayer::FindPresentation (const TopoDS_Shape& theShape,
const View_PresentationType theType) const
{
if (theShape.IsNull())
return Handle(AIS_InteractiveObject)();
NCollection_Shared<AIS_ListOfInteractive> aDisplayed;
DisplayedPresentations (aDisplayed, theType);
for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next())
{
Handle(AIS_Shape) aPresentation = Handle(AIS_Shape)::DownCast (aDisplayedIt.Value());
if (aPresentation->Shape().IsEqual (theShape))
return aPresentation;
}
return Handle(AIS_InteractiveObject)();
}
// =======================================================================
// function : CreatePresentation
// purpose :
// =======================================================================
Handle(Standard_Transient) View_Displayer::CreatePresentation (const TopoDS_Shape& theShape)
{
Handle(AIS_Shape) aShape = new AIS_Shape (theShape);
aShape->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0));
return aShape;
}
// =======================================================================
// function : fitAllView
// purpose :
// =======================================================================
void View_Displayer::fitAllView()
{
Handle(V3d_View) aView = GetView();
if (!aView.IsNull())
{
aView->FitAll();
aView->Redraw();
}
}

View File

@@ -21,6 +21,7 @@
#include <NCollection_DataMap.hxx>
#include <NCollection_Shared.hxx>
#include <TopoDS_Shape.hxx>
#include <Quantity_Color.hxx>
#include <inspector/View_PresentationType.hxx>
@@ -53,6 +54,10 @@ public:
//! \param theToKeepPresentation boolean state
void KeepPresentations (const bool theToKeepPresentations) { myIsKeepPresentations = theToKeepPresentations; }
//! Stores flag whether the FitAll shoud be done automatically for each display
//! \param theFitAllActive boolean value
void SetFitAllActive (const bool theFitAllActive) { myFitAllActive = theFitAllActive; }
//! Stores display mode and changes display mode of displayed presentations
//! \param theDisplayMode a mode: 0 - AIS_WireFrame, 1 - AIS_Shaded
//! \param theType presentation type
@@ -73,6 +78,12 @@ public:
const View_PresentationType theType = View_PresentationType_Main,
const bool theToUpdateViewer = true);
//! Redisplays the parameter presentation in current context
//! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
//! \param isToUpdateView boolean state if viewer should be updated
Standard_EXPORT void RedisplayPresentation (const Handle(Standard_Transient)& thePresentation,
const bool theToUpdateViewer = true);
//! Erases all presentations from viewer. Iterates by internal map of displayed presentations and
//! erase these presentations.
//! \param isToUpdateView boolean state if viewer should be updated
@@ -84,6 +95,25 @@ public:
Standard_EXPORT void ErasePresentations (const View_PresentationType theType = View_PresentationType_Main,
const bool theToUpdateViewer = true);
//! Erase presentation from viewer
//! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
//! \param theType presentation type
//! \param isToUpdateView boolean state if viewer should be updated
Standard_EXPORT void ErasePresentation (const Handle(Standard_Transient)& thePresentation,
const View_PresentationType theType = View_PresentationType_Main,
const bool theToUpdateViewer = true);
//! Sets shape visible/invisible
//! \theShape shape instance
//! \theState visibility state
Standard_EXPORT void SetVisible (const TopoDS_Shape& theShape, const bool theState,
const View_PresentationType theType = View_PresentationType_Main);
//! Returns visibility state value
//! \theShape shape instance
Standard_EXPORT bool IsVisible (const TopoDS_Shape& theShape,
const View_PresentationType theType = View_PresentationType_Main) const;
//! Calls UpdateCurrentViewer of context
Standard_EXPORT void UpdateViewer();
@@ -97,11 +127,23 @@ public:
//! \param thePresentations a container to be filled
//! \param theType presentation type
Standard_EXPORT void DisplayedPresentations (NCollection_Shared<AIS_ListOfInteractive>& thePresentations,
const View_PresentationType theType = View_PresentationType_Main);
const View_PresentationType theType = View_PresentationType_Main) const;
//! Returns all displayed by the trihedron objects
const NCollection_DataMap<View_PresentationType, NCollection_Shared<AIS_ListOfInteractive>>& GetDisplayed() const { return myDisplayed; }
//! Returns presentation if there is displayed AIS_Shape presentation for the parameter shape
//! \param theShape a shape instance
//! \param theType presentation type
//! \return presentation instance or NULL
Standard_EXPORT Handle(AIS_InteractiveObject) FindPresentation (const TopoDS_Shape& theShape,
const View_PresentationType theType = View_PresentationType_Main) const;
//! Creates AIS_Shape for the shape
//! \param theShape a shape
//! \return presentation
Standard_EXPORT static Handle(Standard_Transient) CreatePresentation (const TopoDS_Shape& theShape);
private:
//! Returns the current context
@@ -110,6 +152,9 @@ private:
//! Returns 3d view
Handle(V3d_View) GetView() const;
//! Fit all view
void fitAllView();
private:
Handle(AIS_InteractiveContext) myContext; //!< context, where the displayer works
@@ -117,6 +162,7 @@ private:
NCollection_DataMap<View_PresentationType, Quantity_Color> myColorAttributes; //!< color properties of presentations
bool myIsKeepPresentations; //!< flag if previously shown presentations stays in the context by displaying a new one
bool myFitAllActive; //!< flag if Fit All should be peformed automatically by each Display
int myDisplayMode; //!< display mode: 0 - AIS_WireFrame, 1 - AIS_Shaded
};

View File

@@ -31,7 +31,7 @@ const int DEFAULT_SPACING = 3;
// function : Constructor
// purpose :
// =======================================================================
View_ToolBar::View_ToolBar (QWidget* theParent)
View_ToolBar::View_ToolBar (QWidget* theParent, const bool isUseKeepView)
: QObject (theParent)
{
myMainWindow = new QWidget (theParent);
@@ -63,22 +63,25 @@ View_ToolBar::View_ToolBar (QWidget* theParent)
myViewContexts[View_ContextType_Own] = Handle(AIS_InteractiveContext)();
myViewContexts[View_ContextType_External] = Handle(AIS_InteractiveContext)();
myActionsMap[View_ToolActionType_KeepViewId] = new QToolButton (theParent);
myActionsMap[View_ToolActionType_KeepViewId]->setIcon (QIcon (":/icons/keep_view_on.png"));
myActionsMap[View_ToolActionType_KeepViewId]->setText (tr ("Multi"));
myActionsMap[View_ToolActionType_KeepViewId]->setToolTip (tr ("Keep View On: does not clear previously shown presentation"));
myActionsMap[View_ToolActionType_KeepViewId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
myActionsMap[View_ToolActionType_KeepViewId]->setCheckable (true);
myActionsMap[View_ToolActionType_KeepViewId]->setChecked (false);
if (isUseKeepView)
{
myActionsMap[View_ToolActionType_KeepViewId] = new QToolButton (theParent);
myActionsMap[View_ToolActionType_KeepViewId]->setIcon (QIcon (":/icons/keep_view_on.png"));
myActionsMap[View_ToolActionType_KeepViewId]->setText (tr ("Multi"));
myActionsMap[View_ToolActionType_KeepViewId]->setToolTip (tr ("Keep View On: does not clear previously shown presentation"));
myActionsMap[View_ToolActionType_KeepViewId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
myActionsMap[View_ToolActionType_KeepViewId]->setCheckable (true);
myActionsMap[View_ToolActionType_KeepViewId]->setChecked (false);
myActionsMap[View_ToolActionType_KeepViewOffId] = new QToolButton (theParent);
myActionsMap[View_ToolActionType_KeepViewOffId]->setIcon (QIcon (":/icons/keep_view_off.png"));
myActionsMap[View_ToolActionType_KeepViewOffId]->setText (QObject::tr ("Single"));
myActionsMap[View_ToolActionType_KeepViewOffId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
myActionsMap[View_ToolActionType_KeepViewOffId]->setToolTip (tr ("Keep View Off: clear previously shown presentation"));
myActionsMap[View_ToolActionType_KeepViewOffId]->setCheckable (true);
myActionsMap[View_ToolActionType_KeepViewOffId]->setChecked (true);
}
myActionsMap[View_ToolActionType_KeepViewOffId] = new QToolButton (theParent);
myActionsMap[View_ToolActionType_KeepViewOffId]->setIcon (QIcon (":/icons/keep_view_off.png"));
myActionsMap[View_ToolActionType_KeepViewOffId]->setText (QObject::tr ("Single"));
myActionsMap[View_ToolActionType_KeepViewOffId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
myActionsMap[View_ToolActionType_KeepViewOffId]->setToolTip (tr ("Keep View Off: clear previously shown presentation"));
myActionsMap[View_ToolActionType_KeepViewOffId]->setCheckable (true);
myActionsMap[View_ToolActionType_KeepViewOffId]->setChecked (true);
myActionsMap[View_ToolActionType_ClearViewId] = new QToolButton (theParent);
myActionsMap[View_ToolActionType_ClearViewId]->setIcon (QIcon (":/icons/view_clear.png"));
myActionsMap[View_ToolActionType_ClearViewId]->setText (tr ( "Clear View"));

View File

@@ -44,7 +44,7 @@ class View_ToolBar : public QObject
public:
//! Constructor
Standard_EXPORT View_ToolBar (QWidget* theParent);
Standard_EXPORT View_ToolBar (QWidget* theParent, const bool isUseKeepView = true);
//! Destructor
virtual ~View_ToolBar() Standard_OVERRIDE {}

View File

@@ -0,0 +1,64 @@
// 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.
#ifndef View_ToolButton_H
#define View_ToolButton_H
#include <Standard_WarningsDisable.hxx>
#include <QToolButton>
#include <QMouseEvent>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
//! \class View_Widget
//! \brief It is a Qt control that implements change checked state for button by double click event
//! Button becomes checked by double click mouse pressed and unchecked by the next press mouse
class View_ToolButton : public QToolButton
{
Q_OBJECT
public:
View_ToolButton (QWidget* theParent) : QToolButton (theParent) {}
~View_ToolButton() {}
//! Sets the button checkable, set whether the button checkable or not
//! \param theChecked boolean value
void SetButtonChecked (const bool theChecked) {setCheckable (theChecked); setChecked (theChecked); emit checkedStateChanged (theChecked); }
signals:
//! Sends a signal about checked state is changed
//! \param theState the checked state
void checkedStateChanged (bool theState);
protected:
//! Sets the button unchecked if it was checked
virtual void mousePressEvent (QMouseEvent* theEvent)
{
if (isChecked())
SetButtonChecked (false);
else
QToolButton::mousePressEvent (theEvent);
}
//! Sets the button checked if it was unchecked
virtual void mouseDoubleClickEvent (QMouseEvent* theEvent)
{
QToolButton::mouseDoubleClickEvent (theEvent);
if (!isChecked())
SetButtonChecked (true);
}
};
#endif

76
tools/View/View_Tools.cxx Normal file
View File

@@ -0,0 +1,76 @@
// 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.
#include <inspector/View_Tools.hxx>
#include <inspector/View_Viewer.hxx>
#include <inspector/View_Widget.hxx>
#include <inspector/View_Window.hxx>
#include <V3d_View.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QObject>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : CreateAction
// purpose :
// =======================================================================
QAction* View_Tools::CreateAction (const QString& theText, const char* theSlot, QObject* theParent, QObject* theContext)
{
QAction* anAction = new QAction (theText, theParent);
QObject::connect (anAction, SIGNAL (triggered (bool)), theContext, theSlot);
return anAction;
}
// =======================================================================
// function : SaveState
// purpose :
// =======================================================================
void View_Tools::SaveState (View_Window* theView, QMap<QString, QString>& theItems,
const QString& thePrefix)
{
QStringList aCameraDirection;
Standard_Real aVX, aVY, aVZ;
theView->GetView()->GetViewer()->GetView()->Proj (aVX, aVY, aVZ);
aCameraDirection << QString::number (aVX) << QString::number (aVY) << QString::number (aVZ);
theItems[thePrefix + "view_camera_direction"] = aCameraDirection.join (",");
}
// =======================================================================
// function : RestoreState
// purpose :
// =======================================================================
bool View_Tools::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->GetView()->SetInitProj (aVX, aVY, aVZ);
}
}
else
return false;
return true;
}

65
tools/View/View_Tools.hxx Normal file
View File

@@ -0,0 +1,65 @@
// 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.
#ifndef View_Tools_H
#define View_Tools_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QMap>
#include <QString>
#include <Standard_WarningsRestore.hxx>
class View_Window;
class QAction;
class QObject;
//! \class View_Tools
//! \brief The tool that gives auxiliary methods for qt elements manipulation
class View_Tools
{
public:
//! Creates an action with the given text connected to the slot
//! \param theText an action text value
//! \param theSlot a listener of triggered signal of the new action
//! \param theParent a parent object
//! \param theContext listener of the action toggle
//! \return a new action
Standard_EXPORT static QAction* CreateAction (const QString& theText, const char* theSlot,
QObject* theParent, QObject* theContext);
//! Save state of three view in a container in form: key, value. It saves:
//! - visibiblity of columns,
//! - columns width
//! \param theTreeView a view instance
//! \param theItems [out] properties
//! \param thePrefix peference item prefix
Standard_EXPORT static void SaveState (View_Window* theView, QMap<QString, QString>& theItems,
const QString& thePrefix = QString());
//! Restore state of three view by a container
//! \param theTreeView a view instance
//! \param theKey property key
//! \param theValue property value
//! \param thePrefix peference item prefix
//! \return boolean value whether the property is applyed to the tree view
Standard_EXPORT static bool RestoreState (View_Window* theView, const QString& theKey, const QString& theValue,
const QString& thePrefix = QString());
};
#endif

View File

@@ -19,8 +19,12 @@
#include <inspector/View_Widget.hxx>
#include <AIS_Trihedron.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Standard_Version.hxx>
#include <inspector/View_ToolButton.hxx>
#include <inspector/View_ViewActionType.hxx>
#include <inspector/View_Viewer.hxx>
@@ -59,14 +63,17 @@
// function : Constructor
// purpose :
// =======================================================================
View_Widget::View_Widget (QWidget* theParent)
View_Widget::View_Widget (QWidget* theParent, const bool isFitAllActive)
: QWidget (theParent), myCurrentMode (View_CurrentAction3d_Nothing), myFirst (true), myDefaultWidth (-1),
myDefaultHeight (-1), myViewIsEnabled (true), myXmin (0), myYmin (0), myXmax (0), myYmax (0), myDragButtonDownX (0),
myDragButtonDownY (0), myDragMultiButtonDownX (0), myDragMultiButtonDownY (0), myIsRectVisible (false), myRectBand (0)
myDragButtonDownY (0), myDragMultiButtonDownX (0), myDragMultiButtonDownY (0), myIsRectVisible (false), myRectBand (0),
myHasInitProj (Standard_False), myInitVx (0), myInitVy (0), myInitVz (0)
{
myViewer = new View_Viewer (View_Viewer::DefaultColor());
myViewer->InitStandardViewer();
myViewer->GetContext()->Display(new AIS_Trihedron (new Geom_Axis2Placement (gp::XOY())), Standard_True);
setAttribute (Qt::WA_PaintOnScreen);
setAttribute (Qt::WA_NoSystemBackground);
@@ -76,6 +83,7 @@ View_Widget::View_Widget (QWidget* theParent)
setFocusPolicy (Qt::StrongFocus);
initViewActions();
((View_ToolButton*)myFitAllAction)->SetButtonChecked (isFitAllActive);
initCursors();
}
@@ -116,6 +124,9 @@ void View_Widget::Init()
myViewer->GetView()->SetBackgroundColor (View_Viewer::DefaultColor());
myViewer->GetView()->MustBeResized();
if (myHasInitProj)
myViewer->GetView()->SetProj (myInitVx, myInitVy, myInitVz);
}
// =======================================================================
@@ -133,13 +144,14 @@ int View_Widget::GetDisplayMode() const
// =======================================================================
void View_Widget::paintEvent (QPaintEvent* /*theEvent*/)
{
#if QT_VERSION < 0x050000
#if (QT_VERSION < 0x050000 || QT_VERSION >= 0x050700)
if (myFirst)
{
Init();
myFirst = false;
}
#endif
if (myViewer->GetView())
myViewer->GetView()->Redraw();
}
@@ -150,7 +162,7 @@ void View_Widget::paintEvent (QPaintEvent* /*theEvent*/)
// =======================================================================
void View_Widget::resizeEvent (QResizeEvent* /*theEvent*/)
{
#if QT_VERSION > 0x050000
#if (QT_VERSION > 0x050000 && QT_VERSION < 0x050700)
if (myFirst)
{
Init();
@@ -184,21 +196,33 @@ void View_Widget::SetEnabledView (const bool theIsEnabled)
if (myViewer->GetView())
myViewer->GetView()->SetBackgroundColor (theIsEnabled ? View_Viewer::DefaultColor()
: View_Viewer::DisabledColor());
for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
GetViewAction ((View_ViewActionType)anActionId)->setEnabled (theIsEnabled);
}
// =======================================================================
// function : onCheckedStateChanged
// purpose :
// =======================================================================
void View_Widget::onCheckedStateChanged (bool isOn)
{
QWidget* aSentByAction = (QWidget*)sender();
if (aSentByAction == myFitAllAction)
emit checkedStateChanged(View_ViewActionType_FitAllId, isOn);
}
// =======================================================================
// function : OnUpdateToggled
// purpose :
// =======================================================================
void View_Widget::OnUpdateToggled (bool isOn)
{
QAction* sentBy = (QAction*)sender();
QAction* aSentByAction = (QAction*)sender();
if (sentBy == myViewActions[View_ViewActionType_DisplayModeId])
if (aSentByAction == myViewActions[View_ViewActionType_DisplayModeId])
{
sentBy->setIcon (isOn ? QIcon (":/icons/view_dm_wireframe.png")
aSentByAction->setIcon (isOn ? QIcon (":/icons/view_dm_wireframe.png")
: QIcon (":/icons/view_dm_shading.png"));
return;
}
@@ -206,7 +230,7 @@ void View_Widget::OnUpdateToggled (bool isOn)
if (!isOn)
return;
for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_RotationId; anActionId++)
for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_RotationId; anActionId++)
{
QAction* anAction = myViewActions[(View_ViewActionType)anActionId];
if ((anAction == myViewActions[View_ViewActionType_FitAreaId]) ||
@@ -214,19 +238,19 @@ void View_Widget::OnUpdateToggled (bool isOn)
(anAction == myViewActions[View_ViewActionType_PanId]) ||
(anAction == myViewActions[View_ViewActionType_RotationId]))
{
if (anAction && (anAction != sentBy))
if (anAction && (anAction != aSentByAction))
{
anAction->setChecked (false);
}
else
{
if (sentBy == myViewActions[View_ViewActionType_FitAreaId])
if (aSentByAction == myViewActions[View_ViewActionType_FitAreaId])
setActiveCursor (View_CursorMode_HandCursor);
else if (sentBy == myViewActions[View_ViewActionType_ZoomId])
else if (aSentByAction == myViewActions[View_ViewActionType_ZoomId])
setActiveCursor (View_CursorMode_ZoomCursor);
else if (sentBy == myViewActions[View_ViewActionType_PanId])
else if (aSentByAction == myViewActions[View_ViewActionType_PanId])
setActiveCursor (View_CursorMode_PanCursor);
else if (sentBy == myViewActions[View_ViewActionType_RotationId])
else if (aSentByAction == myViewActions[View_ViewActionType_RotationId])
setActiveCursor (View_CursorMode_RotationCursor);
else
setActiveCursor (View_CursorMode_DefaultCursor);
@@ -244,7 +268,11 @@ void View_Widget::initViewActions()
if (!myViewActions.empty())
return;
myFitAllAction = new View_ToolButton (this); //!< action for automatic fit all
connect (myFitAllAction, SIGNAL (checkedStateChanged(bool)), this, SLOT (onCheckedStateChanged(bool)));
createAction (View_ViewActionType_FitAllId, ":/icons/view_fitall.png", tr ("Fit All"), SLOT (OnFitAll()));
myFitAllAction->setDefaultAction (GetViewAction (View_ViewActionType_FitAllId));
createAction (View_ViewActionType_FitAreaId, ":/icons/view_fitarea.png", tr ("Fit Area"), SLOT (OnFitArea()), true);
createAction (View_ViewActionType_ZoomId, ":/icons/view_zoom.png", tr ("Zoom"), SLOT (OnZoom()), true);
createAction (View_ViewActionType_PanId, ":/icons/view_pan.png", tr ("Pan"), SLOT (OnPan()), true);
@@ -628,7 +656,8 @@ void View_Widget::processInputEvent (const Standard_Integer/* theX*/, const Stan
// =======================================================================
void View_Widget::processMoveEvent (const Standard_Integer theX, const Standard_Integer theY)
{
myViewer->GetContext()->MoveTo (theX, theY, myViewer->GetView(), Standard_True);
if (myViewer->GetView())
myViewer->GetContext()->MoveTo (theX, theY, myViewer->GetView(), Standard_True);
}
// =======================================================================

View File

@@ -25,6 +25,7 @@
#include <QAction>
#include <QMap>
#include <QString>
#include <QToolButton>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
@@ -73,7 +74,7 @@ protected:
public:
//! Constructor
Standard_EXPORT View_Widget (QWidget* theParent);
Standard_EXPORT View_Widget (QWidget* theParent, const bool isFitAllActive);
//! Destructor
virtual ~View_Widget() {}
@@ -88,9 +89,13 @@ public:
Standard_EXPORT void Init();
//! Returns an action for the given action type
//! \param theActionId an action indes
//! \param theActionId an action index
QAction* GetViewAction (const View_ViewActionType theActionId) const { return myViewActions[theActionId]; };
//! Retuns an action widget if exist. Implemented for fit all widget.
//! \param theActionId an action index
QWidget* GetWidget (const View_ViewActionType theActionId) const { return theActionId == View_ViewActionType_FitAllId ? myFitAllAction : 0; };
//! \returns 0 - AIS_WireFrame, 1 - AIS_Shaded
Standard_EXPORT int GetDisplayMode() const;
@@ -98,6 +103,17 @@ public:
//! \param theIsEnabled boolean value
Standard_EXPORT void SetEnabledView (const bool theIsEnabled);
//!< widget for fit all, processed double click to perform action automatically
//! \param theIsEnabled boolean value
bool IsActionChecked (const View_ViewActionType theActionId) { if (theActionId == View_ViewActionType_FitAllId) return myFitAllAction->isChecked(); }
//!< Setx initial camera position
//! \param theVx direction on Ox
//! \param theVy direction on Oy
//! \param theVz direction on Oz
void SetInitProj (const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
{ myHasInitProj = Standard_True; myInitVx = theVx; myInitVy = theVy; myInitVz = theVz; }
//! Get paint engine for the OpenGL viewer. Avoid default execution of Qt Widget.
virtual QPaintEngine* paintEngine() const Standard_OVERRIDE { return 0; }
@@ -112,6 +128,11 @@ signals:
//! Sends a signal about display mode change
void displayModeClicked();
//! Sends a signal about checked state is changed
//! \param theActionId an action index
//! \param theState the checked state
void checkedStateChanged (const int theActionId, bool theState);
public slots:
//! Fits all the V3d view and redraw view
@@ -129,6 +150,11 @@ public slots:
//! Stores state about onRotate to use it by the mouse move
void OnRotate() { myCurrentMode = View_CurrentAction3d_DynamicRotation; }
//! Updates states of widget actions
//!
//! - if the state is checked, uncheck all other actions
Standard_EXPORT void onCheckedStateChanged (bool isOn);
//! Updates states of tool actions:
//! - if the action is display mode, it changes an icon for action(wireframe or shading)
//! - if the state is checked, uncheck all other actions
@@ -256,7 +282,6 @@ protected:
void drawRectangle (const Standard_Integer theMinX, const Standard_Integer theMinY, const Standard_Integer theMaxX,
const Standard_Integer theMaxY, const Standard_Boolean theToDraw);
private:
//! Creates action and stores it in a map of actions
//! \param theActionId an identifier of action in internal map
//! \param theIcon an icon name and place according to qrc resource file, e.g. ":/icons/view_fitall.png"
@@ -274,14 +299,15 @@ private:
private:
View_Viewer* myViewer; //!< connector to context, V3d viewer and V3d View
QToolButton* myFitAllAction; //!< widget for fit all, processed double click to perform action automatically
QMap<View_ViewActionType, QAction*> myViewActions; //!< tool bar view actions
QMap<View_CursorMode, QCursor> myCursors; //!< possible cursors for view actions
View_CurrentAction3d myCurrentMode; //!< an active action mode for viewer
bool myFirst; //!< flag to Init view by the first resize/paint call
int myDefaultWidth; //!< default width for the first sizeHint
int myDefaultHeight; //!< default height for the first sizeHint
bool myViewIsEnabled; //!< flag if the view and tool bar view actions are enabled/disabled
Standard_Boolean myFirst; //!< flag to Init view by the first resize/paint call
Standard_Integer myDefaultWidth; //!< default width for the first sizeHint
Standard_Integer myDefaultHeight; //!< default height for the first sizeHint
Standard_Boolean myViewIsEnabled; //!< flag if the view and tool bar view actions are enabled/disabled
Standard_Integer myXmin; //!< cached X minimal position by mouse press event
Standard_Integer myYmin; //!< cached Y minimal position by mouse press event
Standard_Integer myXmax; //!< cached X maximum position by mouse press event
@@ -292,6 +318,12 @@ private:
Standard_Integer myDragMultiButtonDownY; //!< cached Y button down by multi drag event
Standard_Boolean myIsRectVisible; //!< true if rectangle is visible now
QRubberBand* myRectBand; //!< selection rectangle rubber band
Standard_Boolean myHasInitProj; //!< is initial camera position defined
Standard_Real myInitVx; //!< initial camera position on X
Standard_Real myInitVy; //!< initial camera position on Y
Standard_Real myInitVz; //!< initial camera position on Z
};
#endif

View File

@@ -21,13 +21,17 @@
#include <inspector/View_Displayer.hxx>
#include <inspector/View_ToolBar.hxx>
#include <inspector/View_Tools.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>
@@ -37,26 +41,34 @@ const int DEFAULT_SPACING = 3;
// function : Constructor
// purpose :
// =======================================================================
View_Window::View_Window (QWidget* theParent)
View_Window::View_Window (QWidget* theParent, 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);
myViewToolBar = new View_ToolBar (this);
myView = new View_Widget (this, 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);
for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
myActionsToolBar->addWidget (myView-> GetWidget (View_ViewActionType_FitAllId));
for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
myActionsToolBar->addAction (myView->GetViewAction ((View_ViewActionType)anActionId));
aViewLayout->addWidget (myActionsToolBar, 1, 0);
aViewLayout->addWidget (myView, 1, 1);
aViewLayout->setRowStretch (1, 1);
@@ -65,6 +77,9 @@ View_Window::View_Window (QWidget* theParent)
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();
}
@@ -91,6 +106,8 @@ void View_Window::onViewSelectorActivated()
Handle(AIS_InteractiveContext) aContext = myViewToolBar->GetCurrentContext();
myDisplayer->EraseAllPresentations (true);
emit eraseAllPerformed();
myDisplayer->SetContext (aContext);
}
@@ -115,6 +132,7 @@ void View_Window::onToolBarActionClicked (const int theActionId)
case View_ToolActionType_ClearViewId:
{
myDisplayer->EraseAllPresentations (true);
emit eraseAllPerformed();
break;
}
default:
@@ -122,6 +140,60 @@ void View_Window::onToolBarActionClicked (const int theActionId)
}
}
// =======================================================================
// 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;
anOrientationSubMenu->addAction (View_Tools::CreateAction (V3d::TypeOfOrientationToString (anOrientationType),
SLOT (onSetOrientation()), this, this));
}
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 :

View File

@@ -40,7 +40,7 @@ class View_Window : public QWidget
public:
//! Constructor
Standard_EXPORT View_Window (QWidget* theParent);
Standard_EXPORT View_Window (QWidget* theParent, const bool isUseKeepView = true, const bool isFitAllActive = true);
//! Destructor
virtual ~View_Window() {}
@@ -62,6 +62,10 @@ public:
//! \param theContext an AIS context
Standard_EXPORT void SetContext (View_ContextType theType, const Handle(AIS_InteractiveContext)& theContext);
signals:
//! Signals about calling erasing all presentations in context
void eraseAllPerformed();
protected slots:
//! Processing context change:
@@ -70,9 +74,21 @@ protected slots:
//! - sets the current view enabled only if a current context type is View_ContextType_Own
void onViewSelectorActivated();
//! Processing widget action checked state changed: for Fit All action, if checked, displayer do FitAll automatically
//! \param theActionId a clicked action
//! \param theState a result checked state
void onCheckedStateChanged (int theActionId, bool theState);
//! Processing window tool bar actions
void onToolBarActionClicked (const int theActionId);
//! Shows context menu for view. It contains set view orientation actions.
//! \param thePosition a clicked point
void onViewContextMenuRequested (const QPoint& thePosition);
//! Sets the view scene orientation by the text of selected action
void onSetOrientation();
//! Sets selected display mode in the current context
void onDisplayModeChanged();

View File

@@ -1,64 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg4136"
version="1.1"
inkscape:version="0.91 r13725"
width="16"
height="16"
viewBox="0 0 16 16"
sodipodi:docname="keep_view_off.svg"
shape-rendering="crispEdges"
inkscape:export-filename="D:\Projects\OInspector\Dev\DFBrowser_1.5\src\DFView\icons\keep_view_off.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<metadata
id="metadata4142">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4140" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1310"
inkscape:window-height="884"
id="namedview4138"
showgrid="false"
inkscape:zoom="24.625"
inkscape:cx="0.32877433"
inkscape:cy="7.9357725"
inkscape:window-x="1874"
inkscape:window-y="21"
inkscape:window-maximized="0"
inkscape:current-layer="svg4136" />
<rect
style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
id="rect4178"
width="13.238579"
height="11.939087"
x="1.3807107"
y="2.0710659" />
</svg>

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,78 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg4136"
version="1.1"
inkscape:version="0.91 r13725"
width="16"
height="16"
viewBox="0 0 16 16"
sodipodi:docname="keep_view_on.svg"
shape-rendering="crispEdges"
inkscape:export-filename="D:\Projects\OInspector\Dev\DFBrowser_1.5\src\DFView\icons\keep_view_on.png"
inkscape:export-xdpi="99.009903"
inkscape:export-ydpi="99.009903">
<metadata
id="metadata4142">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4140" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1310"
inkscape:window-height="884"
id="namedview4138"
showgrid="false"
inkscape:zoom="24.625"
inkscape:cx="0.32877433"
inkscape:cy="7.9357725"
inkscape:window-x="1858"
inkscape:window-y="40"
inkscape:window-maximized="1"
inkscape:current-layer="svg4136" />
<rect
style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
id="rect4178"
width="6.8223352"
height="5.7664976"
x="1.1370559"
y="2.0710659" />
<rect
style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
id="rect4188"
width="6.7817259"
height="6.6598983"
x="4.9543152"
y="5.3197966" />
<rect
style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
id="rect4190"
width="6.0913706"
height="5.5228424"
x="8.8527918"
y="9.5837564" />
</svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB