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

Coding - Apply .clang-format formatting #286

Update empty method guards to new style with regex (see PR).
Used clang-format 18.1.8.
New actions to validate code formatting is added.
Update .clang-format with disabling of include sorting.
  It is temporary changes, then include will be sorted.
Apply formatting for /src and /tools folder.
The files with .hxx,.cxx,.lxx,.h,.pxx,.hpp,*.cpp extensions.
This commit is contained in:
dpasukhi
2025-01-25 20:15:22 +00:00
parent dbba6f1289
commit a5a7b3185b
14005 changed files with 1273539 additions and 1195567 deletions

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_Communicator.hxx>

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_Communicator_H
#define ShapeView_Communicator_H
@@ -24,9 +24,12 @@
class ShapeView_Communicator : public TInspectorAPI_Communicator
{
public:
//! Constructor
ShapeView_Communicator() : TInspectorAPI_Communicator(), myWindow (new ShapeView_Window (0)) {}
ShapeView_Communicator()
: TInspectorAPI_Communicator(),
myWindow(new ShapeView_Window(0))
{
}
//! Destructor
virtual ~ShapeView_Communicator() { myWindow->RemoveAllShapes(); }
@@ -34,32 +37,41 @@ public:
//! Provides the container with a parent where this container should be inserted.
//! If Qt implementation, it should be QWidget with QLayout set inside
//! \param theParent a parent class
virtual void SetParent (void* theParent) Standard_OVERRIDE { myWindow->SetParent (theParent); }
virtual void SetParent(void* theParent) Standard_OVERRIDE { myWindow->SetParent(theParent); }
//! Sets parameters container, it should be used when the plugin is initialized or in update content
//! \param theParameters a parameters container
virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE
{ myWindow->SetParameters (theParameters); }
//! Sets parameters container, it should be used when the plugin is initialized or in update
//! content \param theParameters a parameters container
virtual void SetParameters(const Handle(TInspectorAPI_PluginParameters)& theParameters)
Standard_OVERRIDE
{
myWindow->SetParameters(theParameters);
}
//! Provides container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); }
virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE
{
myWindow->FillActionsMenu(theMenu);
}
//! Returns plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->GetPreferences (theItem); }
virtual void GetPreferences(TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{
myWindow->GetPreferences(theItem);
}
//! Stores plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->SetPreferences (theItem); }
virtual void SetPreferences(const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{
myWindow->SetPreferences(theItem);
}
//! Calls update of the plugin's content
virtual void UpdateContent() Standard_OVERRIDE { myWindow->UpdateContent(); }
private:
ShapeView_Window* myWindow; //!< current window
};

View File

@@ -11,8 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_ItemRoot.hxx>
#include <inspector/ShapeView_ItemShape.hxx>
@@ -21,9 +20,9 @@
// function : Shape
// purpose :
// =======================================================================
const TopoDS_Shape& ShapeView_ItemRoot::Shape (const int theRowId)
const TopoDS_Shape& ShapeView_ItemRoot::Shape(const int theRowId)
{
NCollection_List<TopoDS_Shape>::Iterator aShapesIt (myShapes);
NCollection_List<TopoDS_Shape>::Iterator aShapesIt(myShapes);
for (int aRowId = 0; aShapesIt.More(); aShapesIt.Next(), aRowId++)
{
if (aRowId == theRowId)
@@ -51,8 +50,7 @@ QVariant ShapeView_ItemRoot::initValue(const int theRole) const
// function : createChild
// purpose :
// =======================================================================
TreeModel_ItemBasePtr ShapeView_ItemRoot::createChild (int theRow, int theColumn)
TreeModel_ItemBasePtr ShapeView_ItemRoot::createChild(int theRow, int theColumn)
{
return ShapeView_ItemShape::CreateItem (currentItem(), theRow, theColumn);
return ShapeView_ItemShape::CreateItem(currentItem(), theRow, theColumn);
}

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_ItemRoot_H
#define ShapeView_ItemRoot_H
@@ -25,33 +25,35 @@ class ShapeView_ItemRoot;
typedef QExplicitlySharedDataPointer<ShapeView_ItemRoot> ShapeView_ItemRootPtr;
//! \class ShapeView_ItemRoot
//! Collects shapes that should be visualized in tree view. Shapes are cached and if shapes are not needed,
//! cache should be cleared using RemoveAllShapes.
//! Parent is NULL, children are ShapeView_ItemShape items.
//! Collects shapes that should be visualized in tree view. Shapes are cached and if shapes are not
//! needed, cache should be cleared using RemoveAllShapes. Parent is NULL, children are
//! ShapeView_ItemShape items.
class ShapeView_ItemRoot : public TreeModel_ItemBase
{
public:
//! Creates an item wrapped by a shared pointer
static ShapeView_ItemRootPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
{ return ShapeView_ItemRootPtr (new ShapeView_ItemRoot (theParent, theRow, theColumn)); }
static ShapeView_ItemRootPtr CreateItem(TreeModel_ItemBasePtr theParent,
const int theRow,
const int theColumn)
{
return ShapeView_ItemRootPtr(new ShapeView_ItemRoot(theParent, theRow, theColumn));
}
//! Destructor
virtual ~ShapeView_ItemRoot() {}
//! Appends new shape
//! \param theShape a shape instance
void AddShape (const TopoDS_Shape& theShape) { myShapes.Append (theShape); }
void AddShape(const TopoDS_Shape& theShape) { myShapes.Append(theShape); }
//! Clears internal container of added shapes
void RemoveAllShapes() { myShapes.Clear(); }
//! Returns shape by the number
//! \param theRowId an index of the shape in the internal container.
Standard_EXPORT const TopoDS_Shape& Shape (const int theRowId);
Standard_EXPORT const TopoDS_Shape& Shape(const int theRowId);
protected:
//! Returns data value for the role.
//! \param theItemRole a value role
//! \return the value
@@ -64,17 +66,17 @@ protected:
//! \param theRow the child row position
//! \param theColumn the child column position
//! \return the created item
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
virtual TreeModel_ItemBasePtr createChild(int theRow, int theColumn) Standard_OVERRIDE;
private:
//! Constructor
//! \param theParent a parent item
ShapeView_ItemRoot(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: TreeModel_ItemBase (theParent, theRow, theColumn) {}
: TreeModel_ItemBase(theParent, theRow, theColumn)
{
}
private:
NCollection_List<TopoDS_Shape> myShapes; //!< shapes presented in tree view
};

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_ItemShape.hxx>
@@ -36,7 +36,7 @@
// function : Shape
// purpose :
// =======================================================================
TopoDS_Shape ShapeView_ItemShape::Shape (const int theRowId) const
TopoDS_Shape ShapeView_ItemShape::Shape(const int theRowId) const
{
if (myChildShapes.IsEmpty())
{
@@ -48,10 +48,10 @@ TopoDS_Shape ShapeView_ItemShape::Shape (const int theRowId) const
}
else
{
TopoDS_Iterator aSubShapeIt (myShape);
TopoDS_Iterator aSubShapeIt(myShape);
for (int aCurrentIndex = 0; aSubShapeIt.More(); aSubShapeIt.Next(), aCurrentIndex++)
{
aThis->myChildShapes.Add (aSubShapeIt.Value());
aThis->myChildShapes.Add(aSubShapeIt.Value());
}
}
}
@@ -67,7 +67,7 @@ TopoDS_Shape ShapeView_ItemShape::Shape (const int theRowId) const
// =======================================================================
QVariant ShapeView_ItemShape::initValue(const int theRole) const
{
QVariant aParentValue = TreeModel_ItemBase::initValue (theRole);
QVariant aParentValue = TreeModel_ItemBase::initValue(theRole);
if (aParentValue.isValid())
return aParentValue;
@@ -80,8 +80,10 @@ QVariant ShapeView_ItemShape::initValue(const int theRole) const
switch (Column())
{
case 0: return TopAbs::ShapeTypeToString (aShape.ShapeType());
default: break;
case 0:
return TopAbs::ShapeTypeToString(aShape.ShapeType());
default:
break;
}
return QVariant();
}
@@ -115,22 +117,22 @@ int ShapeView_ItemShape::initRowCount() const
// function : initStream
// purpose :
// =======================================================================
void ShapeView_ItemShape::initStream (Standard_OStream& theOStream) const
void ShapeView_ItemShape::initStream(Standard_OStream& theOStream) const
{
TopoDS_Shape aShape = getShape();
if (aShape.IsNull())
return;
aShape.DumpJson (theOStream);
aShape.DumpJson(theOStream);
}
// =======================================================================
// function : createChild
// purpose :
// =======================================================================
TreeModel_ItemBasePtr ShapeView_ItemShape::createChild (int theRow, int theColumn)
TreeModel_ItemBasePtr ShapeView_ItemShape::createChild(int theRow, int theColumn)
{
return ShapeView_ItemShape::CreateItem (currentItem(), theRow, theColumn);
return ShapeView_ItemShape::CreateItem(currentItem(), theRow, theColumn);
}
// =======================================================================
@@ -139,9 +141,9 @@ TreeModel_ItemBasePtr ShapeView_ItemShape::createChild (int theRow, int theColum
// =======================================================================
void ShapeView_ItemShape::Init()
{
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot> (Parent());
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape> (Parent());
myShape = aRootItem ? aRootItem->Shape (Row()) : aShapeItem->Shape (Row());
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(Parent());
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape>(Parent());
myShape = aRootItem ? aRootItem->Shape(Row()) : aShapeItem->Shape(Row());
TreeModel_ItemBase::Init();
}

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_ItemShape_H
#define ShapeView_ItemShape_H
@@ -35,17 +35,21 @@ typedef QExplicitlySharedDataPointer<ShapeView_ItemShape> ShapeView_ItemShapePtr
//! \class ShapeView_ItemShape
//! This item is connected to TopoDS_Shape.
//! Parent is either ShapeView_ItemRoot or ShapeView_ItemShape, children are ShapeView_ItemShape or no children
//! Parent is either ShapeView_ItemRoot or ShapeView_ItemShape, children are ShapeView_ItemShape or
//! no children
class ShapeView_ItemShape : public TreeModel_ItemBase
{
public:
//! Creates an item wrapped by a shared pointer
//! \param theRow the item row position in the parent item
//! \param theColumn the item column position in the parent item
//! \return the pointer to the created item
static ShapeView_ItemShapePtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
{ return ShapeView_ItemShapePtr (new ShapeView_ItemShape (theParent, theRow, theColumn)); }
static ShapeView_ItemShapePtr CreateItem(TreeModel_ItemBasePtr theParent,
const int theRow,
const int theColumn)
{
return ShapeView_ItemShapePtr(new ShapeView_ItemShape(theParent, theRow, theColumn));
}
//! Destructor
virtual ~ShapeView_ItemShape() {}
@@ -55,15 +59,19 @@ public:
//! Sets explore type
//! \param theType type of item explode. If TopAbs_SHAPE, no explode, only iteration by shape
void SetExplodeType (const TopAbs_ShapeEnum theType) { myExplodeType = theType; }
void SetExplodeType(const TopAbs_ShapeEnum theType) { myExplodeType = theType; }
//! Returns the current shape
const TopoDS_Shape& GetItemShape() const { initItem(); return myShape; }
const TopoDS_Shape& GetItemShape() const
{
initItem();
return myShape;
}
//! Returns child(extracted) shape for the current shape by the index
//! \param theRowId an index of child shape
//! \returns shape instance or NULL
Standard_EXPORT TopoDS_Shape Shape (const int theRowId) const;
Standard_EXPORT TopoDS_Shape Shape(const int theRowId) const;
//! Returns name of BREP file for the shape if exists
//! \return string value
@@ -71,7 +79,7 @@ public:
//! Sets name of BREP file for the shape if exists
//! \return string value
void SetFileName (const QString& theFileName) { myFileName = theFileName; }
void SetFileName(const QString& theFileName) { myFileName = theFileName; }
//! Inits the item, fills internal containers
Standard_EXPORT virtual void Init() Standard_OVERRIDE;
@@ -89,10 +97,9 @@ public:
//! Returns stream value of the item to fulfill property panel.
//! \return stream value or dummy
Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE;
Standard_EXPORT virtual void initStream(Standard_OStream& theOStream) const Standard_OVERRIDE;
protected:
//! Initializes the current item. It is empty because Reset() is also empty.
virtual void initItem() const Standard_OVERRIDE;
@@ -100,7 +107,7 @@ protected:
//! \param theRow the child row position
//! \param theColumn the child column position
//! \return the created item
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
virtual TreeModel_ItemBasePtr createChild(int theRow, int theColumn) Standard_OVERRIDE;
//! Returns number of child shapes. Init item if it is not initialized
//! \return integer value
@@ -111,16 +118,18 @@ protected:
TopoDS_Shape getShape() const;
private:
//! Constructor
ShapeView_ItemShape (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: TreeModel_ItemBase (theParent, theRow, theColumn), myExplodeType (TopAbs_SHAPE) {}
ShapeView_ItemShape(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: TreeModel_ItemBase(theParent, theRow, theColumn),
myExplodeType(TopAbs_SHAPE)
{
}
private:
TopAbs_ShapeEnum myExplodeType; //!< type of explore own shape and get children
TopoDS_Shape myShape; //!< current shape
QString myFileName; //!< BREP file name
TopoDS_Shape myShape; //!< current shape
QString myFileName; //!< BREP file name
TopTools_IndexedMapOfShape myChildShapes; //!< cached container of child shapes
};

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_OpenFileDialog.hxx>
#include <inspector/ShapeView_OpenFileViewModel.hxx>
@@ -39,10 +39,10 @@
static const int ICON_SIZE = 40;
static const int OPEN_DIALOG_WIDTH = 550;
static const int OPEN_DIALOG_WIDTH = 550;
static const int OPEN_DIALOG_HEIGHT = 200;
static const int MARGIN_DIALOG = 4;
static const int MARGIN_DIALOG = 4;
static const int SPACING_DIALOG = 2;
// =======================================================================
@@ -54,8 +54,8 @@ QPushButton* ShapeView_OpenButton::StartButton()
if (!myStartButton)
{
myStartButton = new QPushButton();
myStartButton->setIcon (QIcon (":/icons/folder_open.png"));
connect (myStartButton, SIGNAL (clicked()), this, SLOT (onStartButtonClicked()));
myStartButton->setIcon(QIcon(":/icons/folder_open.png"));
connect(myStartButton, SIGNAL(clicked()), this, SLOT(onStartButtonClicked()));
}
return myStartButton;
}
@@ -68,12 +68,12 @@ void ShapeView_OpenButton::onStartButtonClicked()
{
QString aDataDirName = QDir::currentPath();
QString aFileName = ShapeView_OpenFileDialog::OpenFile (0, aDataDirName);
aFileName = QDir().toNativeSeparators (aFileName);
QString aFileName = ShapeView_OpenFileDialog::OpenFile(0, aDataDirName);
aFileName = QDir().toNativeSeparators(aFileName);
if (!aFileName.isEmpty())
{
QApplication::setOverrideCursor (Qt::WaitCursor);
emit OpenFile (aFileName);
QApplication::setOverrideCursor(Qt::WaitCursor);
emit OpenFile(aFileName);
QApplication::restoreOverrideCursor();
}
}
@@ -82,79 +82,82 @@ void ShapeView_OpenButton::onStartButtonClicked()
// function : changeMargins
// purpose :
// =======================================================================
void changeMargins (QBoxLayout* theLayout)
void changeMargins(QBoxLayout* theLayout)
{
theLayout->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG);
theLayout->setSpacing (SPACING_DIALOG);
theLayout->setContentsMargins(MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG);
theLayout->setSpacing(SPACING_DIALOG);
}
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ShapeView_OpenFileDialog::ShapeView_OpenFileDialog (QWidget* theParent, const QString& theDataDirName)
: QDialog (theParent)
ShapeView_OpenFileDialog::ShapeView_OpenFileDialog(QWidget* theParent,
const QString& theDataDirName)
: QDialog(theParent)
{
setWindowTitle (theDataDirName);
setWindowTitle(theDataDirName);
myDataDir = theDataDirName;
QVBoxLayout* aDialogLay = new QVBoxLayout (this);
changeMargins (aDialogLay);
QVBoxLayout* aDialogLay = new QVBoxLayout(this);
changeMargins(aDialogLay);
// Title label
QLabel* aTitleLabel = new QLabel (this);
aTitleLabel->setText (tr ("Open File"));
aDialogLay->addWidget (aTitleLabel);
QLabel* aTitleLabel = new QLabel(this);
aTitleLabel->setText(tr("Open File"));
aDialogLay->addWidget(aTitleLabel);
// Samples View
QGroupBox* aSamplesBox = new QGroupBox (this);
aSamplesBox->setTitle (tr ("Samples"));
aDialogLay->addWidget (aSamplesBox);
QVBoxLayout* aSampleLay = new QVBoxLayout (aSamplesBox);
changeMargins (aSampleLay);
mySamplesView = createTableView (readSampleNames());
aSampleLay->addWidget (mySamplesView);
QGroupBox* aSamplesBox = new QGroupBox(this);
aSamplesBox->setTitle(tr("Samples"));
aDialogLay->addWidget(aSamplesBox);
QVBoxLayout* aSampleLay = new QVBoxLayout(aSamplesBox);
changeMargins(aSampleLay);
mySamplesView = createTableView(readSampleNames());
aSampleLay->addWidget(mySamplesView);
// Select file
QGroupBox* aSelectFileBox = new QGroupBox (this);
aSelectFileBox->setTitle (tr ("Select file"));
aDialogLay->addWidget (aSelectFileBox);
QGridLayout* aSelectFileLay = new QGridLayout (aSelectFileBox);
aSelectFileLay->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG);
QGroupBox* aSelectFileBox = new QGroupBox(this);
aSelectFileBox->setTitle(tr("Select file"));
aDialogLay->addWidget(aSelectFileBox);
QGridLayout* aSelectFileLay = new QGridLayout(aSelectFileBox);
aSelectFileLay->setContentsMargins(MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG);
mySelectedName = new QLineEdit (aSelectFileBox);
QCompleter* aCompleter = new QCompleter();
mySelectedName = new QLineEdit(aSelectFileBox);
QCompleter* aCompleter = new QCompleter();
QFileSystemModel* aFileSystemModel = new QFileSystemModel;
aFileSystemModel->setRootPath (QDir::rootPath());
aCompleter->setModel (aFileSystemModel);
mySelectedName->setCompleter (aCompleter);
aSelectFileLay->addWidget (mySelectedName, 1, 0);
aFileSystemModel->setRootPath(QDir::rootPath());
aCompleter->setModel(aFileSystemModel);
mySelectedName->setCompleter(aCompleter);
aSelectFileLay->addWidget(mySelectedName, 1, 0);
QToolButton* aSelectFileBtn = new QToolButton (aSelectFileBox);
aSelectFileBtn->setIcon (QIcon (":/icons/folder_open.png"));
aSelectFileLay->addWidget (aSelectFileBtn, 1, 1);
QToolButton* aSelectFileBtn = new QToolButton(aSelectFileBox);
aSelectFileBtn->setIcon(QIcon(":/icons/folder_open.png"));
aSelectFileLay->addWidget(aSelectFileBtn, 1, 1);
myFolderApplyOpen = new QToolButton (aSelectFileBox);
myFolderApplyOpen->setIcon (QIcon (":/icons/folder_import.png"));
myFolderApplyOpen->setIconSize (QSize (ICON_SIZE, ICON_SIZE));
myFolderApplyOpen->setEnabled (false);
aSelectFileLay->addWidget (myFolderApplyOpen, 0, 2, 2, 1);
myFolderApplyOpen = new QToolButton(aSelectFileBox);
myFolderApplyOpen->setIcon(QIcon(":/icons/folder_import.png"));
myFolderApplyOpen->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
myFolderApplyOpen->setEnabled(false);
aSelectFileLay->addWidget(myFolderApplyOpen, 0, 2, 2, 1);
connect (mySelectedName, SIGNAL (textChanged (const QString&)),
this, SLOT (onNameChanged (const QString&)));
connect (aSelectFileBtn, SIGNAL (clicked()), this, SLOT (onSelectClicked()));
connect (myFolderApplyOpen, SIGNAL (clicked()), this, SLOT (onApplySelectClicked()));
connect(mySelectedName,
SIGNAL(textChanged(const QString&)),
this,
SLOT(onNameChanged(const QString&)));
connect(aSelectFileBtn, SIGNAL(clicked()), this, SLOT(onSelectClicked()));
connect(myFolderApplyOpen, SIGNAL(clicked()), this, SLOT(onApplySelectClicked()));
resize (OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT);
resize(OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT);
}
// =======================================================================
// function : OpenFile
// purpose :
// =======================================================================
QString ShapeView_OpenFileDialog::OpenFile (QWidget* theParent, const QString& theDataDirName)
QString ShapeView_OpenFileDialog::OpenFile(QWidget* theParent, const QString& theDataDirName)
{
QString aFileName;
QString aFileName;
ShapeView_OpenFileDialog* aDialog = new ShapeView_OpenFileDialog(theParent, theDataDirName);
if (aDialog->exec() == QDialog::Accepted)
aFileName = aDialog->GetFileName();
@@ -166,8 +169,8 @@ QString ShapeView_OpenFileDialog::OpenFile (QWidget* theParent, const QString& t
// function : onSampleSelectionChanged
// purpose :
// =======================================================================
void ShapeView_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& theSelected,
const QItemSelection&)
void ShapeView_OpenFileDialog::onSampleSelectionChanged(const QItemSelection& theSelected,
const QItemSelection&)
{
QItemSelectionModel* aSelectionModel = (QItemSelectionModel*)sender();
if (!aSelectionModel)
@@ -179,7 +182,7 @@ void ShapeView_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& t
if (!anIndex.isValid())
return;
myFileName = aSelectionModel->model()->data (anIndex, Qt::ToolTipRole).toString();
myFileName = aSelectionModel->model()->data(anIndex, Qt::ToolTipRole).toString();
accept();
}
@@ -187,11 +190,11 @@ void ShapeView_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& t
// function : onNameChanged
// purpose :
// =======================================================================
void ShapeView_OpenFileDialog::onNameChanged (const QString& theText)
void ShapeView_OpenFileDialog::onNameChanged(const QString& theText)
{
QFileInfo aFileInfo (theText);
bool anExists = aFileInfo.exists() && aFileInfo.isFile();
myFolderApplyOpen->setEnabled (anExists);
QFileInfo aFileInfo(theText);
bool anExists = aFileInfo.exists() && aFileInfo.isFile();
myFolderApplyOpen->setEnabled(anExists);
}
// =======================================================================
@@ -204,19 +207,19 @@ void ShapeView_OpenFileDialog::onSelectClicked()
QString aDirName = mySelectedName->text();
if (!aDirName.isEmpty())
{
QDir aDir (aDirName);
QDir aDir(aDirName);
if (aDir.exists())
anEnteredPath = aDirName;
}
QString aFilter (tr ("BREP file (*.brep*)"));
QString aFileName = QFileDialog::getOpenFileName (0, "Open document", anEnteredPath, aFilter);
QString aFilter(tr("BREP file (*.brep*)"));
QString aFileName = QFileDialog::getOpenFileName(0, "Open document", anEnteredPath, aFilter);
if (aFileName.isEmpty())
return; // do nothing, left the previous value
mySelectedName->setText (aFileName);
onNameChanged (aFileName);
mySelectedName->setText(aFileName);
onNameChanged(aFileName);
}
// =======================================================================
@@ -233,30 +236,33 @@ void ShapeView_OpenFileDialog::onApplySelectClicked()
// function : createTableView
// purpose :
// =======================================================================
QTableView* ShapeView_OpenFileDialog::createTableView (const QStringList& theFileNames)
QTableView* ShapeView_OpenFileDialog::createTableView(const QStringList& theFileNames)
{
QTableView* aTableView = new QTableView (this);
aTableView->setFrameStyle (QFrame::NoFrame);
QPalette aPalette = aTableView->viewport()->palette();
QColor aWindowColor = aPalette.color (QPalette::Window);
aPalette.setBrush (QPalette::Base, aWindowColor);
aTableView->viewport()->setPalette (aPalette);
QTableView* aTableView = new QTableView(this);
aTableView->setFrameStyle(QFrame::NoFrame);
QPalette aPalette = aTableView->viewport()->palette();
QColor aWindowColor = aPalette.color(QPalette::Window);
aPalette.setBrush(QPalette::Base, aWindowColor);
aTableView->viewport()->setPalette(aPalette);
aTableView->horizontalHeader()->setVisible (false);
aTableView->verticalHeader()->setVisible (false);
aTableView->setGridStyle (Qt::NoPen);
aTableView->setModel (createModel (theFileNames));
aTableView->setItemDelegateForRow (0, new ShapeView_OpenFileItemDelegate (aTableView,
aPalette.color (QPalette::Highlight)));
aTableView->viewport()->setAttribute (Qt::WA_Hover);
aTableView->horizontalHeader()->setVisible(false);
aTableView->verticalHeader()->setVisible(false);
aTableView->setGridStyle(Qt::NoPen);
aTableView->setModel(createModel(theFileNames));
aTableView->setItemDelegateForRow(
0,
new ShapeView_OpenFileItemDelegate(aTableView, aPalette.color(QPalette::Highlight)));
aTableView->viewport()->setAttribute(Qt::WA_Hover);
int aCellHeight = ICON_SIZE + aTableView->verticalHeader()->defaultSectionSize();
aTableView->setRowHeight (0, aCellHeight);
aTableView->setRowHeight(0, aCellHeight);
int aScrollHeight = aTableView->horizontalScrollBar()->sizeHint().height();
aTableView->setMinimumHeight (aCellHeight + aScrollHeight);
QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aTableView->model());
connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
this, SLOT (onSampleSelectionChanged (const QItemSelection&, const QItemSelection&)));
aTableView->setSelectionModel (aSelectionModel);
aTableView->setMinimumHeight(aCellHeight + aScrollHeight);
QItemSelectionModel* aSelectionModel = new QItemSelectionModel(aTableView->model());
connect(aSelectionModel,
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this,
SLOT(onSampleSelectionChanged(const QItemSelection&, const QItemSelection&)));
aTableView->setSelectionModel(aSelectionModel);
return aTableView;
}
@@ -265,10 +271,10 @@ QTableView* ShapeView_OpenFileDialog::createTableView (const QStringList& theFil
// function : createModel
// purpose :
// =======================================================================
QAbstractItemModel* ShapeView_OpenFileDialog::createModel (const QStringList& theFileNames)
QAbstractItemModel* ShapeView_OpenFileDialog::createModel(const QStringList& theFileNames)
{
ShapeView_OpenFileViewModel* aModel = new ShapeView_OpenFileViewModel(this);
aModel->Init (theFileNames);
aModel->Init(theFileNames);
return aModel;
}
@@ -280,15 +286,15 @@ QStringList ShapeView_OpenFileDialog::readSampleNames()
{
QStringList aNames;
QDir aDir (myDataDir);
QDir aDir(myDataDir);
aDir.setSorting(QDir::Name);
QFileInfoList aDirEntries = aDir.entryInfoList();
for (int aDirId = 0; aDirId < aDirEntries.size(); ++aDirId)
{
QFileInfo aFileInfo = aDirEntries.at (aDirId);
QFileInfo aFileInfo = aDirEntries.at(aDirId);
if (aFileInfo.isFile())
aNames.append (aFileInfo.absoluteFilePath());
aNames.append(aFileInfo.absoluteFilePath());
}
return aNames;
}

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_OpenFileDialog_H
#define ShapeView_OpenFileDialog_H
@@ -36,58 +36,65 @@ class QToolButton;
class QWidget;
//! \class ShapeView_OpenButton
//! Class that contains push button and the button processing. It obtains a file name from the default or current
//! directory and gives the name into TInspector communicator
//! Object name of the button is the name of the plugin to get the default directory, or the current directory is used.
//! Class that contains push button and the button processing. It obtains a file name from the
//! default or current directory and gives the name into TInspector communicator Object name of the
//! button is the name of the plugin to get the default directory, or the current directory is used.
class ShapeView_OpenButton : public QObject
{
Q_OBJECT
public:
//! Constructor
ShapeView_OpenButton (QObject* theParent) : QObject (theParent), myStartButton (0) {}
ShapeView_OpenButton(QObject* theParent)
: QObject(theParent),
myStartButton(0)
{
}
//! Destructor
virtual ~ShapeView_OpenButton() {}
//! Returns the start button, if this is the first call, it creates the button and connect it to the slot
//! Returns the start button, if this is the first call, it creates the button and connect it to
//! the slot
Standard_EXPORT QPushButton* StartButton();
//! Sets the default directory of plugin.
void SetPluginDir (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theDefaultDir)
{ myDefaultDirs[thePluginName] = theDefaultDir; }
void SetPluginDir(const TCollection_AsciiString& thePluginName,
const TCollection_AsciiString& theDefaultDir)
{
myDefaultDirs[thePluginName] = theDefaultDir;
}
private slots:
//! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator
//! Processes the button click, open default/current directory to select open file, calls OpenFile
//! of communicator
void onStartButtonClicked();
signals:
//! Signals about opening file clicked
//! \param theFileName an output file name
void OpenFile (const QString& theFileName);
void OpenFile(const QString& theFileName);
private:
QPushButton* myStartButton; //!< processed button
std::map<TCollection_AsciiString, TCollection_AsciiString> myDefaultDirs; //!< plugins default directories
std::map<TCollection_AsciiString, TCollection_AsciiString>
myDefaultDirs; //!< plugins default directories
};
//! \class ShapeView_OpenFileDialog
//! Control that contains table view of samples and line to select a file name from other directory.
//! Click on element of samples table view calls this sample opening else after entering(or opening) file name
//! the import becomes active. Click on the button will open selected file if it is possible
//! Click on element of samples table view calls this sample opening else after entering(or opening)
//! file name the import becomes active. Click on the button will open selected file if it is
//! possible
class ShapeView_OpenFileDialog : public QDialog
{
Q_OBJECT
private:
//! Constructor
ShapeView_OpenFileDialog (QWidget* theParent, const QString& theDataDirName);
ShapeView_OpenFileDialog(QWidget* theParent, const QString& theDataDirName);
public:
//! Destructor
virtual ~ShapeView_OpenFileDialog() Standard_OVERRIDE {}
@@ -95,7 +102,7 @@ public:
//! \param theParent a parent for the new dialog
//! \param theDataDirName path to default samples directory
//! \returns a file name from the open file dialog
static QString OpenFile (QWidget* theParent, const QString& theDataDirName);
static QString OpenFile(QWidget* theParent, const QString& theDataDirName);
//! Returns selection name from the dialog
QString GetFileName() const { return myFileName; }
@@ -103,11 +110,12 @@ public:
private slots:
//! Stores name of selected sample file
void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
void onSampleSelectionChanged(const QItemSelection& theSelected,
const QItemSelection& theDeselected);
//! Updates enabling state of Open file button, it is enabled if the file by the entered path exists
//! \param theText a file name text in line edit
void onNameChanged (const QString& theText);
//! Updates enabling state of Open file button, it is enabled if the file by the entered path
//! exists \param theText a file name text in line edit
void onNameChanged(const QString& theText);
//! Open file dialog to select a file name. Fills file name line, enable import button
void onSelectClicked();
@@ -116,27 +124,25 @@ private slots:
void onApplySelectClicked();
private:
//! Creates view of file names in samples directory
//! \param theFileNames a container of names
//! \return table view
QTableView* createTableView (const QStringList& theFileNames);
QTableView* createTableView(const QStringList& theFileNames);
//! Creates view model and fills it by the file names
//! \param theFileNames a container of names
//! \return model
QAbstractItemModel* createModel (const QStringList& theFileNames);
QAbstractItemModel* createModel(const QStringList& theFileNames);
//! Generates container of file names in samples directory
//! \return container of names
QStringList readSampleNames();
private:
QString myDataDir; //!< samples directory
QString myFileName; //!< result file name
QTableView* mySamplesView; //!< view of sample file names
QLineEdit* mySelectedName; //!< alternative control to open file
QString myDataDir; //!< samples directory
QString myFileName; //!< result file name
QTableView* mySamplesView; //!< view of sample file names
QLineEdit* mySelectedName; //!< alternative control to open file
QToolButton* myFolderApplyOpen; //!< button to open file
};

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_OpenFileViewModel.hxx>
@@ -23,36 +23,38 @@
#include <Standard_WarningsRestore.hxx>
const int ICON_SIZE = 40;
// =======================================================================
// function : paint
// purpose :
// =======================================================================
void ShapeView_OpenFileItemDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
const QModelIndex& theIndex) const
void ShapeView_OpenFileItemDelegate::paint(QPainter* thePainter,
const QStyleOptionViewItem& theOption,
const QModelIndex& theIndex) const
{
// highlight cell
if (theOption.state & QStyle::State_MouseOver)
thePainter->fillRect (theOption.rect, myColor);
thePainter->fillRect(theOption.rect, myColor);
// action icon for all indices before the last one
QIcon anIcon (":/icons/folder_import.png");
QSize anIconSize (ICON_SIZE, ICON_SIZE);
int aDX = (theOption.rect.width() - anIconSize.width()) / 2;
int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin);
thePainter->drawPixmap (QRect (theOption.rect.left() + aDX,
theOption.rect.top() + aMargin,
anIconSize.width(),
anIconSize.height()),
anIcon.pixmap(anIconSize.width(), anIconSize.height()));
QIcon anIcon(":/icons/folder_import.png");
QSize anIconSize(ICON_SIZE, ICON_SIZE);
int aDX = (theOption.rect.width() - anIconSize.width()) / 2;
int aMargin = qApp->style()->pixelMetric(QStyle::PM_HeaderMargin);
thePainter->drawPixmap(QRect(theOption.rect.left() + aDX,
theOption.rect.top() + aMargin,
anIconSize.width(),
anIconSize.height()),
anIcon.pixmap(anIconSize.width(), anIconSize.height()));
// default paint
QItemDelegate::paint (thePainter, theOption, theIndex);
QItemDelegate::paint(thePainter, theOption, theIndex);
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void ShapeView_OpenFileViewModel::Init (const QStringList& theValues)
void ShapeView_OpenFileViewModel::Init(const QStringList& theValues)
{
myValues = theValues;
}
@@ -61,13 +63,16 @@ void ShapeView_OpenFileViewModel::Init (const QStringList& theValues)
// function : data
// purpose :
// =======================================================================
QVariant ShapeView_OpenFileViewModel::data (const QModelIndex& theIndex, int theRole) const
QVariant ShapeView_OpenFileViewModel::data(const QModelIndex& theIndex, int theRole) const
{
switch (theRole)
{
case Qt::DisplayRole: return QFileInfo (myValues[theIndex.column()]).fileName();
case Qt::ToolTipRole: return myValues[theIndex.column()];
case Qt::TextAlignmentRole: return QVariant (Qt::AlignBottom | Qt::AlignHCenter);
case Qt::DisplayRole:
return QFileInfo(myValues[theIndex.column()]).fileName();
case Qt::ToolTipRole:
return myValues[theIndex.column()];
case Qt::TextAlignmentRole:
return QVariant(Qt::AlignBottom | Qt::AlignHCenter);
default:
break;
}

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_OpenFileViewModel_H
#define ShapeView_OpenFileViewModel_H
@@ -29,14 +29,17 @@ class QObject;
class QPainter;
//! \class ShapeView_OpenFileItemDelegate
//! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over button
//! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over
//! button
class ShapeView_OpenFileItemDelegate : public QItemDelegate
{
public:
//! Constructor
ShapeView_OpenFileItemDelegate (QObject* theParent, const QColor& theHighlight)
: QItemDelegate (theParent), myColor(theHighlight) {}
ShapeView_OpenFileItemDelegate(QObject* theParent, const QColor& theHighlight)
: QItemDelegate(theParent),
myColor(theHighlight)
{
}
//! Destructor
virtual ~ShapeView_OpenFileItemDelegate() {}
@@ -45,11 +48,11 @@ public:
//! \param thePainter a painter
//! \param theOption a paint options
//! \param theIndex a view index
Standard_EXPORT void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
const QModelIndex& theIndex) const;
Standard_EXPORT void paint(QPainter* thePainter,
const QStyleOptionViewItem& theOption,
const QModelIndex& theIndex) const;
private:
QColor myColor; //!< highlight color
};
@@ -59,38 +62,44 @@ private:
class ShapeView_OpenFileViewModel : public QAbstractTableModel
{
public:
//! Constructor
ShapeView_OpenFileViewModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {}
ShapeView_OpenFileViewModel(QObject* theParent = 0)
: QAbstractTableModel(theParent)
{
}
//! Destructor
virtual ~ShapeView_OpenFileViewModel() {}
//! Stores values
//! \param theValues a container of values to fill model
void Init (const QStringList& theValues);
void Init(const QStringList& theValues);
//! Returns content of the model index for the given role, it is obtained from internal container of values
//! It returns value only for DisplayRole.
//! \param theIndex a model index
//! \param theRole a view role
//! \return value interpreted depending on the given role
virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
//! Returns content of the model index for the given role, it is obtained from internal container
//! of values It returns value only for DisplayRole. \param theIndex a model index \param theRole
//! a view role \return value interpreted depending on the given role
virtual QVariant data(const QModelIndex& theIndex,
int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
//! Returns number of rows
//! \param theParent an index of the parent item
//! \return an integer value
virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 1; }
virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{
(void)theParent;
return 1;
}
//! Returns number of columns
//! \param theParent an index of the parent item
//! \return an integer value
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return myValues.size(); }
virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{
(void)theParent;
return myValues.size();
}
private:
QStringList myValues; //!< file names
};

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_Tools.hxx>
#include <inspector/ShapeView_ItemShape.hxx>
@@ -26,21 +26,22 @@
// function : IsPossibleToExplode
// purpose :
// =======================================================================
Standard_Boolean ShapeView_Tools::IsPossibleToExplode (const TopoDS_Shape& theShape,
Standard_Boolean ShapeView_Tools::IsPossibleToExplode(
const TopoDS_Shape& theShape,
NCollection_List<TopAbs_ShapeEnum>& theExplodeTypes)
{
TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
if (!theExplodeTypes.Contains (aShapeType))
if (!theExplodeTypes.Contains(aShapeType))
theExplodeTypes.Append(aShapeType);
if (theExplodeTypes.Extent() == TopAbs_SHAPE + 1) // all types are collected, stop
return Standard_True;
TopoDS_Iterator aSubShapeIt (theShape);
TopoDS_Iterator aSubShapeIt(theShape);
for (int aCurrentIndex = 0; aSubShapeIt.More(); aSubShapeIt.Next(), aCurrentIndex++)
{
if (IsPossibleToExplode (aSubShapeIt.Value(), theExplodeTypes))
if (IsPossibleToExplode(aSubShapeIt.Value(), theExplodeTypes))
return Standard_True;
}
return Standard_False;

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_Tools_H
#define ShapeView_Tools_H
@@ -38,14 +38,13 @@
class ShapeView_Tools
{
public:
//! Checks whether it is possible to explode the shape. The search is recursive until all types are collected.
//! \param[in] theShape source shape object
//! \param[out] theExplodeTypes container of possible shape types to be exploded
//! \return true if explode is finished, all types are collected.
Standard_EXPORT static Standard_Boolean IsPossibleToExplode(const TopoDS_Shape& theShape,
//! Checks whether it is possible to explode the shape. The search is recursive until all types
//! are collected. \param[in] theShape source shape object \param[out] theExplodeTypes container
//! of possible shape types to be exploded \return true if explode is finished, all types are
//! collected.
Standard_EXPORT static Standard_Boolean IsPossibleToExplode(
const TopoDS_Shape& theShape,
NCollection_List<TopAbs_ShapeEnum>& theExplodeTypes);
};
#endif

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_TreeModel.hxx>
#include <inspector/ShapeView_ItemRoot.hxx>
@@ -23,8 +23,8 @@
// function : Constructor
// purpose :
// =======================================================================
ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent)
: TreeModel_ModelBase (theParent)
ShapeView_TreeModel::ShapeView_TreeModel(QObject* theParent)
: TreeModel_ModelBase(theParent)
{
}
@@ -32,9 +32,9 @@ ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent)
// function : createRootItem
// purpose :
// =======================================================================
TreeModel_ItemBasePtr ShapeView_TreeModel::createRootItem (const int theColumnId)
TreeModel_ItemBasePtr ShapeView_TreeModel::createRootItem(const int theColumnId)
{
return ShapeView_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId);
return ShapeView_ItemRoot::CreateItem(TreeModel_ItemBasePtr(), 0, theColumnId);
}
// =======================================================================
@@ -45,7 +45,7 @@ void ShapeView_TreeModel::AddShape(const TopoDS_Shape& theShape)
{
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
{
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem (aColId));
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem(aColId));
aRootItem->AddShape(theShape);
}
@@ -61,7 +61,7 @@ void ShapeView_TreeModel::RemoveAllShapes()
{
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
{
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem (aColId));
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem(aColId));
aRootItem->RemoveAllShapes();
}
Reset();
@@ -72,14 +72,16 @@ void ShapeView_TreeModel::RemoveAllShapes()
// function : FindIndex
// purpose :
// =======================================================================
QModelIndex ShapeView_TreeModel::FindIndex (const TopoDS_Shape& theShape) const
QModelIndex ShapeView_TreeModel::FindIndex(const TopoDS_Shape& theShape) const
{
QModelIndex aParentIndex = index (0, 0);
TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // application item
QModelIndex aParentIndex = index(0, 0);
TreeModel_ItemBasePtr aParentItem =
TreeModel_ModelBase::GetItemByIndex(aParentIndex); // application item
for (int aChildId = 0, aCount = aParentItem->rowCount(); aChildId < aCount; aChildId++)
{
QModelIndex anIndex = index (aChildId, 0, aParentIndex);
ShapeView_ItemShapePtr anItem = itemDynamicCast<ShapeView_ItemShape> (TreeModel_ModelBase::GetItemByIndex (anIndex));
QModelIndex anIndex = index(aChildId, 0, aParentIndex);
ShapeView_ItemShapePtr anItem =
itemDynamicCast<ShapeView_ItemShape>(TreeModel_ModelBase::GetItemByIndex(anIndex));
if (anItem && anItem->GetItemShape() == theShape)
return anIndex;
}

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_TreeModel_H
#define ShapeView_TreeModel_H
@@ -33,16 +33,15 @@ class ShapeView_TreeModel;
class ShapeView_TreeModel : public TreeModel_ModelBase
{
public:
//! Constructor
Standard_EXPORT ShapeView_TreeModel (QObject* theParent);
Standard_EXPORT ShapeView_TreeModel(QObject* theParent);
//! Destructor
virtual ~ShapeView_TreeModel() {}
//! Adds shape, append it to the model root item
//! \param theShape a shape instance
Standard_EXPORT void AddShape (const TopoDS_Shape& theShape);
Standard_EXPORT void AddShape(const TopoDS_Shape& theShape);
//! Removes all shapes in the model root item
Standard_EXPORT void RemoveAllShapes();
@@ -50,13 +49,13 @@ public:
//! Returns model index of the shape.
//! \param theShape a shape object
//! \return the model index
QModelIndex FindIndex (const TopoDS_Shape& theShape) const;
QModelIndex FindIndex(const TopoDS_Shape& theShape) const;
protected:
//! Creates root item
//! \param theColumnId index of a column
Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE;
Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem(const int theColumnId)
Standard_OVERRIDE;
};
#endif

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_VisibilityState.hxx>
@@ -21,26 +21,28 @@
// function : OnClicked
// purpose :
// =======================================================================
void ShapeView_VisibilityState::OnClicked (const QModelIndex& theIndex)
void ShapeView_VisibilityState::OnClicked(const QModelIndex& theIndex)
{
processClicked (theIndex);
emit itemClicked (theIndex);
processClicked(theIndex);
emit itemClicked(theIndex);
}
// =======================================================================
// function : SetVisible
// purpose :
// =======================================================================
bool ShapeView_VisibilityState::SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged)
bool ShapeView_VisibilityState::SetVisible(const QModelIndex& theIndex,
const bool theState,
const bool toEmitDataChanged)
{
TopoDS_Shape aShape = Shape (theIndex);
TopoDS_Shape aShape = Shape(theIndex);
if (aShape.IsNull())
return false;
myDisplayer->SetVisible (aShape, theState, myPresentationType);
myDisplayer->SetVisible(aShape, theState, myPresentationType);
if (toEmitDataChanged)
getModel()->EmitDataChanged (theIndex, theIndex);
getModel()->EmitDataChanged(theIndex, theIndex);
return true;
}
@@ -48,9 +50,9 @@ bool ShapeView_VisibilityState::SetVisible (const QModelIndex& theIndex, const b
// function : Shape
// purpose :
// =======================================================================
TopoDS_Shape ShapeView_VisibilityState::Shape (const QModelIndex& theIndex) const
TopoDS_Shape ShapeView_VisibilityState::Shape(const QModelIndex& theIndex) const
{
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theIndex);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(theIndex);
if (!anItemBase)
return TopoDS_Shape();

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_VisibilityState_H
#define ShapeView_VisibilityState_H
@@ -33,55 +33,65 @@ class ShapeView_VisibilityState : public QObject, public TreeModel_VisibilitySta
Q_OBJECT
public:
//! Constructor
ShapeView_VisibilityState (TreeModel_ModelBase* theModel) : TreeModel_VisibilityState (theModel),
myPresentationType (View_PresentationType_Main) {}
ShapeView_VisibilityState(TreeModel_ModelBase* theModel)
: TreeModel_VisibilityState(theModel),
myPresentationType(View_PresentationType_Main)
{
}
//! Destructor
~ShapeView_VisibilityState() {}
//! Sets current displayer
//! \theDisplayer class that provides connection to visualized objects
void SetDisplayer (View_Displayer* theDisplayer) { myDisplayer = theDisplayer; }
void SetDisplayer(View_Displayer* theDisplayer) { myDisplayer = theDisplayer; }
//! Sets presentation type for displayer
//! \param theType type value
void SetPresentationType (const View_PresentationType theType) { myPresentationType = theType; }
void SetPresentationType(const View_PresentationType theType) { myPresentationType = theType; }
//! Returns true if visibility of the item can be changed
//! \param theIndex tree model index
//! \return boolean value
virtual bool CanBeVisible (const QModelIndex& theIndex) const Standard_OVERRIDE { return !Shape (theIndex).IsNull(); }
virtual bool CanBeVisible(const QModelIndex& theIndex) const Standard_OVERRIDE
{
return !Shape(theIndex).IsNull();
}
//! Sets visibility state
//! \theIndex tree model index
//! \param theState visibility state
//! \param toEmitDataChanged boolean flag whether emit of the model should be done immediately
//! \return true if state is changed
Standard_EXPORT virtual bool SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged) Standard_OVERRIDE;
Standard_EXPORT virtual bool SetVisible(const QModelIndex& theIndex,
const bool theState,
const bool toEmitDataChanged) Standard_OVERRIDE;
//! Returns visibility state value
virtual bool IsVisible (const QModelIndex& theIndex) const Standard_OVERRIDE
{ return myDisplayer->IsVisible (Shape (theIndex), myPresentationType); }
virtual bool IsVisible(const QModelIndex& theIndex) const Standard_OVERRIDE
{
return myDisplayer->IsVisible(Shape(theIndex), myPresentationType);
}
public slots:
//! Processes the mouse clicked on the index.
//! It changes the item visibility if model allows to change it.
//! \theIndex tree model index
void OnClicked (const QModelIndex& theIndex);
void OnClicked(const QModelIndex& theIndex);
signals:
//! Signal after OnClicked is performed
//! \theIndex tree model index
void itemClicked (const QModelIndex& theIndex);
void itemClicked(const QModelIndex& theIndex);
protected:
//! Gets shape of the view model by the parameter index if it has a shape
//! \param theIndex tree model index
//! \return shape instance
TopoDS_Shape Shape (const QModelIndex& theIndex) const;
TopoDS_Shape Shape(const QModelIndex& theIndex) const;
private:
View_Displayer* myDisplayer; //!< view displayer
View_Displayer* myDisplayer; //!< view displayer
View_PresentationType myPresentationType; //!< presentation type
};

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#include <inspector/ShapeView_Window.hxx>
#include <inspector/ShapeView_ItemRoot.hxx>
@@ -62,100 +62,106 @@
#include <QVBoxLayout>
#include <Standard_WarningsRestore.hxx>
static const int DEFAULT_SHAPE_VIEW_WIDTH = 900;
static const int DEFAULT_SHAPE_VIEW_HEIGHT = 450;
static const int DEFAULT_SHAPE_VIEW_WIDTH = 900;
static const int DEFAULT_SHAPE_VIEW_HEIGHT = 450;
static const int DEFAULT_SHAPE_VIEW_POSITION_X = 60;
static const int DEFAULT_SHAPE_VIEW_POSITION_Y = 60;
static const int SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH = 600;
static const int SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH = 600;
static const int SHAPEVIEW_DEFAULT_TREE_VIEW_HEIGHT = 500;
static const int SHAPEVIEW_DEFAULT_VIEW_WIDTH = 300;
static const int SHAPEVIEW_DEFAULT_VIEW_WIDTH = 300;
static const int SHAPEVIEW_DEFAULT_VIEW_HEIGHT = 1000;
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ShapeView_Window::ShapeView_Window (QWidget* theParent)
: QObject (theParent)
ShapeView_Window::ShapeView_Window(QWidget* theParent)
: QObject(theParent)
{
myMainWindow = new QMainWindow (theParent);
myMainWindow = new QMainWindow(theParent);
myTreeView = new ViewControl_TreeView (myMainWindow);
((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH,
SHAPEVIEW_DEFAULT_TREE_VIEW_HEIGHT));
myTreeView->setContextMenuPolicy (Qt::CustomContextMenu);
connect (myTreeView, SIGNAL (customContextMenuRequested (const QPoint&)),
this, SLOT (onTreeViewContextMenuRequested (const QPoint&)));
new TreeModel_ContextMenu (myTreeView);
ShapeView_TreeModel* aModel = new ShapeView_TreeModel (myTreeView);
myTreeView = new ViewControl_TreeView(myMainWindow);
((ViewControl_TreeView*)myTreeView)
->SetPredefinedSize(
QSize(SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH, SHAPEVIEW_DEFAULT_TREE_VIEW_HEIGHT));
myTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(myTreeView,
SIGNAL(customContextMenuRequested(const QPoint&)),
this,
SLOT(onTreeViewContextMenuRequested(const QPoint&)));
new TreeModel_ContextMenu(myTreeView);
ShapeView_TreeModel* aModel = new ShapeView_TreeModel(myTreeView);
aModel->InitColumns();
myTreeView->setModel (aModel);
ShapeView_VisibilityState* aVisibilityState = new ShapeView_VisibilityState (aModel);
aModel->SetVisibilityState (aVisibilityState);
TreeModel_Tools::UseVisibilityColumn (myTreeView);
QObject::connect (myTreeView, SIGNAL (clicked (const QModelIndex&)),
aVisibilityState, SLOT (OnClicked(const QModelIndex&)));
myTreeView->setModel(aModel);
ShapeView_VisibilityState* aVisibilityState = new ShapeView_VisibilityState(aModel);
aModel->SetVisibilityState(aVisibilityState);
TreeModel_Tools::UseVisibilityColumn(myTreeView);
QObject::connect(myTreeView,
SIGNAL(clicked(const QModelIndex&)),
aVisibilityState,
SLOT(OnClicked(const QModelIndex&)));
QItemSelectionModel* aSelModel = new QItemSelectionModel (myTreeView->model(), myTreeView);
myTreeView->setSelectionModel (aSelModel);
connect (aSelModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
QItemSelectionModel* aSelModel = new QItemSelectionModel(myTreeView->model(), myTreeView);
myTreeView->setSelectionModel(aSelModel);
connect(aSelModel,
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this,
SLOT(onTreeViewSelectionChanged(const QItemSelection&, const QItemSelection&)));
QModelIndex aParentIndex = myTreeView->model()->index (0, 0);
myTreeView->setExpanded (aParentIndex, true);
myMainWindow->setCentralWidget (myTreeView);
QModelIndex aParentIndex = myTreeView->model()->index(0, 0);
myTreeView->setExpanded(aParentIndex, true);
myMainWindow->setCentralWidget(myTreeView);
// property view
myPropertyView = new ViewControl_PropertyView (myMainWindow,
myPropertyView = new ViewControl_PropertyView(
myMainWindow,
QSize(SHAPEVIEW_DEFAULT_VIEW_WIDTH, SHAPEVIEW_DEFAULT_VIEW_HEIGHT));
myPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel"), myMainWindow);
myPropertyPanelWidget->setObjectName (myPropertyPanelWidget->windowTitle());
myPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow));
myPropertyPanelWidget->setWidget (myPropertyView->GetControl());
myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myPropertyPanelWidget);
myPropertyPanelWidget = new QDockWidget(tr("PropertyPanel"), myMainWindow);
myPropertyPanelWidget->setObjectName(myPropertyPanelWidget->windowTitle());
myPropertyPanelWidget->setTitleBarWidget(new QWidget(myMainWindow));
myPropertyPanelWidget->setWidget(myPropertyView->GetControl());
myMainWindow->addDockWidget(Qt::RightDockWidgetArea, myPropertyPanelWidget);
// view
myViewWindow = new View_Window (myMainWindow, NULL, false);
connect (myViewWindow, SIGNAL(eraseAllPerformed()), this, SLOT(onEraseAllPerformed()));
aVisibilityState->SetDisplayer (myViewWindow->Displayer());
aVisibilityState->SetPresentationType (View_PresentationType_Main);
myViewWindow->SetPredefinedSize (SHAPEVIEW_DEFAULT_VIEW_WIDTH, SHAPEVIEW_DEFAULT_VIEW_HEIGHT);
myViewWindow = new View_Window(myMainWindow, NULL, false);
connect(myViewWindow, SIGNAL(eraseAllPerformed()), this, SLOT(onEraseAllPerformed()));
aVisibilityState->SetDisplayer(myViewWindow->Displayer());
aVisibilityState->SetPresentationType(View_PresentationType_Main);
myViewWindow->SetPredefinedSize(SHAPEVIEW_DEFAULT_VIEW_WIDTH, SHAPEVIEW_DEFAULT_VIEW_HEIGHT);
QDockWidget* aViewDockWidget = new QDockWidget (tr ("View"), myMainWindow);
aViewDockWidget->setObjectName (aViewDockWidget->windowTitle());
aViewDockWidget->setWidget (myViewWindow);
aViewDockWidget->setTitleBarWidget (myViewWindow->ViewToolBar()->GetControl());
myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aViewDockWidget);
QDockWidget* aViewDockWidget = new QDockWidget(tr("View"), myMainWindow);
aViewDockWidget->setObjectName(aViewDockWidget->windowTitle());
aViewDockWidget->setWidget(myViewWindow);
aViewDockWidget->setTitleBarWidget(myViewWindow->ViewToolBar()->GetControl());
myMainWindow->addDockWidget(Qt::RightDockWidgetArea, aViewDockWidget);
myMainWindow->splitDockWidget(myPropertyPanelWidget, aViewDockWidget, Qt::Vertical);
myMainWindow->resize (DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT);
myMainWindow->move (DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y);
myMainWindow->resize(DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT);
myMainWindow->move(DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y);
}
// =======================================================================
// function : Destructor
// purpose :
// =======================================================================
ShapeView_Window::~ShapeView_Window()
{
}
ShapeView_Window::~ShapeView_Window() {}
// =======================================================================
// function : SetParent
// purpose :
// =======================================================================
void ShapeView_Window::SetParent (void* theParent)
void ShapeView_Window::SetParent(void* theParent)
{
QWidget* aParent = (QWidget*)theParent;
if (aParent)
{
QLayout* aLayout = aParent->layout();
if (aLayout)
aLayout->addWidget (GetMainWindow());
aLayout->addWidget(GetMainWindow());
}
}
@@ -163,15 +169,15 @@ void ShapeView_Window::SetParent (void* theParent)
// function : FillActionsMenu
// purpose :
// =======================================================================
void ShapeView_Window::FillActionsMenu (void* theMenu)
void ShapeView_Window::FillActionsMenu(void* theMenu)
{
QMenu* aMenu = (QMenu*)theMenu;
QMenu* aMenu = (QMenu*)theMenu;
QList<QDockWidget*> aDockwidgets = myMainWindow->findChildren<QDockWidget*>();
for (QList<QDockWidget*>::iterator it = aDockwidgets.begin(); it != aDockwidgets.end(); ++it)
{
QDockWidget* aDockWidget = *it;
if (aDockWidget->parentWidget() == myMainWindow)
aMenu->addAction (aDockWidget->toggleViewAction());
aMenu->addAction(aDockWidget->toggleViewAction());
}
}
@@ -179,36 +185,44 @@ void ShapeView_Window::FillActionsMenu (void* theMenu)
// function : GetPreferences
// purpose :
// =======================================================================
void ShapeView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
void ShapeView_Window::GetPreferences(TInspectorAPI_PreferencesDataMap& theItem)
{
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
theItem.Bind("geometry",
TreeModel_Tools::ToString(myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;
TreeModel_Tools::SaveState (myTreeView, anItems);
TreeModel_Tools::SaveState(myTreeView, anItems);
View_Window::SaveState(myViewWindow, anItems);
for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++)
theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin();
anItemsIt != anItems.end();
anItemsIt++)
theItem.Bind(anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
}
// =======================================================================
// function : SetPreferences
// purpose :
// =======================================================================
void ShapeView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
void ShapeView_Window::SetPreferences(const TInspectorAPI_PreferencesDataMap& theItem)
{
if (theItem.IsEmpty())
{
TreeModel_Tools::SetDefaultHeaderSections (myTreeView);
TreeModel_Tools::SetDefaultHeaderSections(myTreeView);
return;
}
for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (theItem); anItemIt.More(); anItemIt.Next())
for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt(theItem); anItemIt.More();
anItemIt.Next())
{
if (anItemIt.Key().IsEqual ("geometry"))
myMainWindow->restoreState (TreeModel_Tools::ToByteArray (anItemIt.Value().ToCString()));
else if (TreeModel_Tools::RestoreState (myTreeView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
if (anItemIt.Key().IsEqual("geometry"))
myMainWindow->restoreState(TreeModel_Tools::ToByteArray(anItemIt.Value().ToCString()));
else if (TreeModel_Tools::RestoreState(myTreeView,
anItemIt.Key().ToCString(),
anItemIt.Value().ToCString()))
continue;
else if (View_Window::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
else if (View_Window::RestoreState(myViewWindow,
anItemIt.Key().ToCString(),
anItemIt.Value().ToCString()))
continue;
}
}
@@ -220,47 +234,50 @@ void ShapeView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& t
void ShapeView_Window::UpdateContent()
{
TCollection_AsciiString aName = "TKShapeView";
if (myParameters->FindParameters (aName))
if (myParameters->FindParameters(aName))
{
NCollection_List<Handle(Standard_Transient)> aParameters = myParameters->Parameters (aName);
NCollection_List<Handle(Standard_Transient)> aParameters = myParameters->Parameters(aName);
// Init will remove from parameters those, that are processed only one time (TShape)
Init(aParameters);
myParameters->SetParameters (aName, aParameters);
myParameters->SetParameters(aName, aParameters);
}
if (myParameters->FindFileNames(aName))
{
for (NCollection_List<TCollection_AsciiString>::Iterator aFilesIt(myParameters->FileNames(aName));
aFilesIt.More(); aFilesIt.Next())
OpenFile (aFilesIt.Value());
for (NCollection_List<TCollection_AsciiString>::Iterator aFilesIt(
myParameters->FileNames(aName));
aFilesIt.More();
aFilesIt.Next())
OpenFile(aFilesIt.Value());
NCollection_List<TCollection_AsciiString> aNames;
myParameters->SetFileNames (aName, aNames);
myParameters->SetFileNames(aName, aNames);
}
// make TopoDS_TShape selected if exist in select parameters
NCollection_List<Handle(Standard_Transient)> anObjects;
if (myParameters->GetSelectedObjects(aName, anObjects))
{
ShapeView_TreeModel* aModel = dynamic_cast<ShapeView_TreeModel*> (myTreeView->model());
ShapeView_TreeModel* aModel = dynamic_cast<ShapeView_TreeModel*>(myTreeView->model());
QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
aSelectionModel->clear();
for (NCollection_List<Handle(Standard_Transient)>::Iterator aParamsIt (anObjects);
aParamsIt.More(); aParamsIt.Next())
for (NCollection_List<Handle(Standard_Transient)>::Iterator aParamsIt(anObjects);
aParamsIt.More();
aParamsIt.Next())
{
Handle(Standard_Transient) anObject = aParamsIt.Value();
Handle(TopoDS_TShape) aShapePointer = Handle(TopoDS_TShape)::DownCast (anObject);
Handle(Standard_Transient) anObject = aParamsIt.Value();
Handle(TopoDS_TShape) aShapePointer = Handle(TopoDS_TShape)::DownCast(anObject);
if (aShapePointer.IsNull())
continue;
TopoDS_Shape aShape;
aShape.TShape (aShapePointer);
aShape.TShape(aShapePointer);
QModelIndex aShapeIndex = aModel->FindIndex (aShape);
QModelIndex aShapeIndex = aModel->FindIndex(aShape);
if (!aShapeIndex.isValid())
continue;
aSelectionModel->select (aShapeIndex, QItemSelectionModel::Select);
myTreeView->scrollTo (aShapeIndex);
aSelectionModel->select(aShapeIndex, QItemSelectionModel::Select);
myTreeView->scrollTo(aShapeIndex);
}
myParameters->SetSelected (aName, NCollection_List<Handle(Standard_Transient)>());
myParameters->SetSelected(aName, NCollection_List<Handle(Standard_Transient)>());
}
}
@@ -268,46 +285,47 @@ void ShapeView_Window::UpdateContent()
// function : Init
// purpose :
// =======================================================================
void ShapeView_Window::Init (NCollection_List<Handle(Standard_Transient)>& theParameters)
void ShapeView_Window::Init(NCollection_List<Handle(Standard_Transient)>& theParameters)
{
Handle(AIS_InteractiveContext) aContext;
Handle(AIS_InteractiveContext) aContext;
NCollection_List<Handle(Standard_Transient)> aParameters;
TCollection_AsciiString aPluginName ("TKShapeView");
TCollection_AsciiString aPluginName("TKShapeView");
NCollection_List<TCollection_AsciiString> aSelectedParameters;
if (myParameters->FindSelectedNames (aPluginName)) // selected names have TShape parameters
aSelectedParameters = myParameters->GetSelectedNames (aPluginName);
if (myParameters->FindSelectedNames(aPluginName)) // selected names have TShape parameters
aSelectedParameters = myParameters->GetSelectedNames(aPluginName);
NCollection_List<TCollection_AsciiString>::Iterator aParamsIt (aSelectedParameters);
for (NCollection_List<Handle(Standard_Transient)>::Iterator anObjectsIt (theParameters);
anObjectsIt.More(); anObjectsIt.Next())
NCollection_List<TCollection_AsciiString>::Iterator aParamsIt(aSelectedParameters);
for (NCollection_List<Handle(Standard_Transient)>::Iterator anObjectsIt(theParameters);
anObjectsIt.More();
anObjectsIt.Next())
{
Handle(Standard_Transient) anObject = anObjectsIt.Value();
Handle(TopoDS_TShape) aShapePointer = Handle(TopoDS_TShape)::DownCast (anObject);
Handle(Standard_Transient) anObject = anObjectsIt.Value();
Handle(TopoDS_TShape) aShapePointer = Handle(TopoDS_TShape)::DownCast(anObject);
if (!aShapePointer.IsNull())
{
TopoDS_Shape aShape;
aShape.TShape (aShapePointer);
aShape.TShape(aShapePointer);
if (aParamsIt.More())
{
// each Transient object has own location/orientation description
TInspectorAPI_PluginParameters::ParametersToShape (aParamsIt.Value(), aShape);
TInspectorAPI_PluginParameters::ParametersToShape(aParamsIt.Value(), aShape);
aParamsIt.Next();
}
addShape (aShape);
addShape(aShape);
}
else
{
aParameters.Append (anObject);
aParameters.Append(anObject);
if (aContext.IsNull())
aContext = Handle(AIS_InteractiveContext)::DownCast (anObject);
aContext = Handle(AIS_InteractiveContext)::DownCast(anObject);
}
}
if (!aContext.IsNull())
myViewWindow->SetContext (View_ContextType_External, aContext);
myViewWindow->SetContext(View_ContextType_External, aContext);
theParameters = aParameters;
myParameters->SetSelectedNames (aPluginName, NCollection_List<TCollection_AsciiString>());
myParameters->SetSelectedNames(aPluginName, NCollection_List<TCollection_AsciiString>());
}
// =======================================================================
@@ -316,7 +334,7 @@ void ShapeView_Window::Init (NCollection_List<Handle(Standard_Transient)>& thePa
// =======================================================================
void ShapeView_Window::OpenFile(const TCollection_AsciiString& theFileName)
{
TopoDS_Shape aShape = Convert_Tools::ReadShape (theFileName);
TopoDS_Shape aShape = Convert_Tools::ReadShape(theFileName);
if (!aShape.IsNull())
addShape(aShape);
}
@@ -327,7 +345,7 @@ void ShapeView_Window::OpenFile(const TCollection_AsciiString& theFileName)
// =======================================================================
void ShapeView_Window::RemoveAllShapes()
{
ShapeView_TreeModel* aModel = dynamic_cast<ShapeView_TreeModel*> (myTreeView->model());
ShapeView_TreeModel* aModel = dynamic_cast<ShapeView_TreeModel*>(myTreeView->model());
aModel->RemoveAllShapes();
}
@@ -335,76 +353,89 @@ void ShapeView_Window::RemoveAllShapes()
// function : addShape
// purpose :
// =======================================================================
void ShapeView_Window::addShape (const TopoDS_Shape& theShape)
void ShapeView_Window::addShape(const TopoDS_Shape& theShape)
{
ShapeView_TreeModel* aModel = dynamic_cast<ShapeView_TreeModel*> (myTreeView->model());
aModel->AddShape (theShape);
ShapeView_TreeModel* aModel = dynamic_cast<ShapeView_TreeModel*>(myTreeView->model());
aModel->AddShape(theShape);
}
// =======================================================================
// function : onTreeViewContextMenuRequested
// purpose :
// =======================================================================
void ShapeView_Window::onTreeViewContextMenuRequested (const QPoint& thePosition)
void ShapeView_Window::onTreeViewContextMenuRequested(const QPoint& thePosition)
{
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
return;
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
return;
QMenu* aMenu = new QMenu(myMainWindow);
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot> (anItemBase);
if (aRootItem) {
aMenu->addAction (ViewControl_Tools::CreateAction ("Load BREP file", SLOT (onLoadFile()), myMainWindow, this));
aMenu->addAction (ViewControl_Tools::CreateAction ("Remove all shape items", SLOT (onClearView()), myMainWindow, this));
QMenu* aMenu = new QMenu(myMainWindow);
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(anItemBase);
if (aRootItem)
{
aMenu->addAction(
ViewControl_Tools::CreateAction("Load BREP file", SLOT(onLoadFile()), myMainWindow, this));
aMenu->addAction(ViewControl_Tools::CreateAction("Remove all shape items",
SLOT(onClearView()),
myMainWindow,
this));
}
else {
aMenu->addAction (ViewControl_Tools::CreateAction ("Export to BREP", SLOT (onExportToBREP()), myMainWindow, this));
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape>(anItemBase);
const TopoDS_Shape& aShape = aShapeItem->GetItemShape();
TopAbs_ShapeEnum anExplodeType = aShapeItem->ExplodeType();
else
{
aMenu->addAction(ViewControl_Tools::CreateAction("Export to BREP",
SLOT(onExportToBREP()),
myMainWindow,
this));
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape>(anItemBase);
const TopoDS_Shape& aShape = aShapeItem->GetItemShape();
TopAbs_ShapeEnum anExplodeType = aShapeItem->ExplodeType();
NCollection_List<TopAbs_ShapeEnum> anExplodeTypes;
ShapeView_Tools::IsPossibleToExplode (aShape, anExplodeTypes);
ShapeView_Tools::IsPossibleToExplode(aShape, anExplodeTypes);
if (anExplodeTypes.Size() > 0)
{
QMenu* anExplodeMenu = aMenu->addMenu ("Explode");
for (NCollection_List<TopAbs_ShapeEnum>::Iterator anExpIterator (anExplodeTypes); anExpIterator.More();
anExpIterator.Next())
QMenu* anExplodeMenu = aMenu->addMenu("Explode");
for (NCollection_List<TopAbs_ShapeEnum>::Iterator anExpIterator(anExplodeTypes);
anExpIterator.More();
anExpIterator.Next())
{
TopAbs_ShapeEnum aType = anExpIterator.Value();
QAction* anAction = ViewControl_Tools::CreateAction (TopAbs::ShapeTypeToString (aType), SLOT (onExplode()), myMainWindow, this);
anExplodeMenu->addAction (anAction);
QAction* anAction = ViewControl_Tools::CreateAction(TopAbs::ShapeTypeToString(aType),
SLOT(onExplode()),
myMainWindow,
this);
anExplodeMenu->addAction(anAction);
if (anExplodeType == aType)
{
anAction->setCheckable (true);
anAction->setChecked (true);
anAction->setCheckable(true);
anAction->setChecked(true);
}
}
QAction* anAction = ViewControl_Tools::CreateAction ("NONE", SLOT (onExplode()), myMainWindow, this);
QAction* anAction =
ViewControl_Tools::CreateAction("NONE", SLOT(onExplode()), myMainWindow, this);
anExplodeMenu->addSeparator();
anExplodeMenu->addAction (anAction);
anExplodeMenu->addAction(anAction);
}
}
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
aMenu->exec (aPoint);
QPoint aPoint = myTreeView->mapToGlobal(thePosition);
aMenu->exec(aPoint);
}
// =======================================================================
// function : onTreeViewSelectionChanged
// purpose :
// =======================================================================
void ShapeView_Window::onTreeViewSelectionChanged (const QItemSelection&,
const QItemSelection&)
void ShapeView_Window::onTreeViewSelectionChanged(const QItemSelection&, const QItemSelection&)
{
QApplication::setOverrideCursor (Qt::WaitCursor);
QApplication::setOverrideCursor(Qt::WaitCursor);
if (myPropertyPanelWidget->toggleViewAction()->isChecked())
myPropertyView->Init (ViewControl_Tools::CreateTableModelValues (myTreeView->selectionModel()));
myPropertyView->Init(ViewControl_Tools::CreateTableModelValues(myTreeView->selectionModel()));
QApplication::restoreOverrideCursor();
}
@@ -415,9 +446,10 @@ void ShapeView_Window::onTreeViewSelectionChanged (const QItemSelection&,
// =======================================================================
void ShapeView_Window::onEraseAllPerformed()
{
ShapeView_TreeModel* aTreeModel = dynamic_cast<ShapeView_TreeModel*> (myTreeView->model());
ShapeView_TreeModel* aTreeModel = dynamic_cast<ShapeView_TreeModel*>(myTreeView->model());
// TODO: provide update for only visibility state for better performance TopoDS_Shape myCustomShape;
// TODO: provide update for only visibility state for better performance TopoDS_Shape
// myCustomShape;
aTreeModel->Reset();
aTreeModel->EmitLayoutChanged();
@@ -433,7 +465,7 @@ void ShapeView_Window::onExplode()
if (!aModel)
return;
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex);
if (!anItemBase)
return;
@@ -446,7 +478,7 @@ void ShapeView_Window::onExplode()
if (!anAction)
return;
QApplication::setOverrideCursor (Qt::WaitCursor);
QApplication::setOverrideCursor(Qt::WaitCursor);
TopAbs_ShapeEnum aShapeType;
if (anAction->text() == "NONE")
aShapeType = TopAbs_SHAPE;
@@ -456,8 +488,8 @@ void ShapeView_Window::onExplode()
myViewWindow->Displayer()->EraseAllPresentations();
aShapeItem->SetExplodeType(aShapeType);
//anItemBase->Parent()->Reset(); - TODO (update only modified sub-tree)
ShapeView_TreeModel* aTreeModel = dynamic_cast<ShapeView_TreeModel*> (myTreeView->model());
// anItemBase->Parent()->Reset(); - TODO (update only modified sub-tree)
ShapeView_TreeModel* aTreeModel = dynamic_cast<ShapeView_TreeModel*>(myTreeView->model());
aTreeModel->Reset();
aTreeModel->EmitLayoutChanged();
QApplication::restoreOverrideCursor();
@@ -472,11 +504,11 @@ void ShapeView_Window::onLoadFile()
QString aDataDirName = QDir::currentPath();
QString aFileName = ShapeView_OpenFileDialog::OpenFile(0, aDataDirName);
aFileName = QDir().toNativeSeparators (aFileName);
aFileName = QDir().toNativeSeparators(aFileName);
if (aFileName.isEmpty())
return;
QApplication::setOverrideCursor (Qt::WaitCursor);
QApplication::setOverrideCursor(Qt::WaitCursor);
onOpenFile(aFileName);
QApplication::restoreOverrideCursor();
}
@@ -487,9 +519,13 @@ void ShapeView_Window::onLoadFile()
// =======================================================================
void ShapeView_Window::onExportToBREP()
{
QString aFilter (tr ("Boundary representation file (*.brep *)"));
QString aFilter(tr("Boundary representation file (*.brep *)"));
QString aSelectedFilter;
QString aFileName = QFileDialog::getSaveFileName (0, tr ("Export shape to file"), QString(), aFilter, &aSelectedFilter);
QString aFileName = QFileDialog::getSaveFileName(0,
tr("Export shape to file"),
QString(),
aFilter,
&aSelectedFilter);
QItemSelectionModel* aModel = myTreeView->selectionModel();
if (!aModel)
@@ -499,8 +535,8 @@ void ShapeView_Window::onExportToBREP()
if (aSelectedRows.size() == 0)
return;
QModelIndex aSelectedIndex = aSelectedRows.at (0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (aSelectedIndex);
QModelIndex aSelectedIndex = aSelectedRows.at(0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(aSelectedIndex);
if (!anItemBase)
return;
@@ -509,8 +545,8 @@ void ShapeView_Window::onExportToBREP()
return;
TCollection_AsciiString aFileNameIndiced = aFileName.toStdString().c_str();
const TopoDS_Shape& aShape = anItem->GetItemShape();
BRepTools::Write (aShape, aFileNameIndiced.ToCString());
anItem->SetFileName (aFileNameIndiced.ToCString());
const TopoDS_Shape& aShape = anItem->GetItemShape();
BRepTools::Write(aShape, aFileNameIndiced.ToCString());
anItem->SetFileName(aFileNameIndiced.ToCString());
aFileName = aFileNameIndiced.ToCString();
}

View File

@@ -11,7 +11,7 @@
// 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.
// commercial license or contractual agreement.
#ifndef ShapeView_Window_H
#define ShapeView_Window_H
@@ -46,9 +46,8 @@ class ShapeView_Window : public QObject
{
Q_OBJECT
public:
//! Constructor
Standard_EXPORT ShapeView_Window (QWidget* theParent);
Standard_EXPORT ShapeView_Window(QWidget* theParent);
//! Destructor
Standard_EXPORT virtual ~ShapeView_Window();
@@ -56,25 +55,29 @@ public:
//! Provides the container with a parent where this container should be inserted.
//! If Qt implementation, it should be QWidget with QLayout set inside
//! \param theParent a parent class
Standard_EXPORT void SetParent (void* theParent);
Standard_EXPORT void SetParent(void* theParent);
//! Sets parameters container, it should be used when the plugin is initialized or in update content
//! \param theParameters a parameters container
void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
//! Sets parameters container, it should be used when the plugin is initialized or in update
//! content \param theParameters a parameters container
void SetParameters(const Handle(TInspectorAPI_PluginParameters)& theParameters)
{
myParameters = theParameters;
}
//! Provides container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
Standard_EXPORT virtual void FillActionsMenu(void* theMenu);
//! Returns plugin preferences: dock widgets state, tree view columns.
//! \param theItem container of preference elements
Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
Standard_EXPORT void GetPreferences(TInspectorAPI_PreferencesDataMap& theItem);
//! Applies plugin preferences
//! \param theItem container of preference elements
Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
Standard_EXPORT void SetPreferences(const TInspectorAPI_PreferencesDataMap& theItem);
//! Applies parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
//! Applies parameters to Init controls, opens files if there are in parameters, updates OCAF tree
//! view model
Standard_EXPORT void UpdateContent();
//! Returns main control
@@ -89,30 +92,29 @@ public:
protected:
//! Appends shape into tree view model
//! \param theShape a shape instance
Standard_EXPORT void addShape (const TopoDS_Shape& theShape);
Standard_EXPORT void addShape(const TopoDS_Shape& theShape);
private:
//! Fills controls of the plugin by parameters:
//! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
//! \param theParameters a parameters container
void Init (NCollection_List<Handle(Standard_Transient)>& theParameters);
void Init(NCollection_List<Handle(Standard_Transient)>& theParameters);
//! Reads Shape from the file name, add Shape into tree view
//! \param theFileName BREP file name
void OpenFile (const TCollection_AsciiString& theFileName);
void OpenFile(const TCollection_AsciiString& theFileName);
protected slots:
//! Shows context menu for tree view selected item. It contains expand/collapse actions.
//! \param thePosition a clicked point
void onTreeViewContextMenuRequested (const QPoint& thePosition);
void onTreeViewContextMenuRequested(const QPoint& thePosition);
//! Processes selection in tree view: make presentation or owner selected in the context if corresponding
//! check box is checked
//! \param theSelected a selected items
//! \param theDeselected a deselected items
void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
//! Processes selection in tree view: make presentation or owner selected in the context if
//! corresponding check box is checked \param theSelected a selected items \param theDeselected a
//! deselected items
void onTreeViewSelectionChanged(const QItemSelection& theSelected,
const QItemSelection& theDeselected);
//! Updates visibility states by erase all in context
void onEraseAllPerformed();
@@ -131,23 +133,26 @@ protected slots:
//! Converts file name to Ascii String and perform opening file
//! \param theFileName a file name to be opened
void onOpenFile(const QString& theFileName) { OpenFile (TCollection_AsciiString (theFileName.toUtf8().data())); }
void onOpenFile(const QString& theFileName)
{
OpenFile(TCollection_AsciiString(theFileName.toUtf8().data()));
}
protected:
//! Creates new action and connect it to the given slot
//! \param theText an action text
//! \param theSlot a listener method
QAction* createAction (const QString& theText, const char* theSlot);
QAction* createAction(const QString& theText, const char* theSlot);
private:
QMainWindow* myMainWindow; //!< main control, parent for all ShapeView controls
QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget
ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist
ViewControl_PropertyView*
myPropertyView; //!< property control to display model item values if exist
View_Window* myViewWindow; //!< OCC 3d view to visualize presentations
QTreeView* myTreeView; //!< tree view visualized shapes
QTreeView* myTreeView; //!< tree view visualized shapes
Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
};