File: DFBrowser_AttributePaneStack.cxx

package info (click to toggle)
opencascade 7.9.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 301,924 kB
  • sloc: cpp: 1,523,264; tcl: 10,159; cs: 5,173; java: 1,554; sh: 1,342; ansic: 827; xml: 699; makefile: 30; javascript: 22
file content (153 lines) | stat: -rw-r--r-- 5,563 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// 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/DFBrowser_AttributePaneStack.hxx>

#include <inspector/DFBrowserPane_AttributePaneAPI.hxx>
#include <inspector/DFBrowserPane_AttributePaneSelector.hxx>
#include <inspector/DFBrowser_Item.hxx>
#include <inspector/DFBrowser_Module.hxx>
#include <inspector/DFBrowser_Tools.hxx>
#include <inspector/DFBrowser_TreeLevelView.hxx>
#include <inspector/DFBrowser_TreeModel.hxx>
#include <inspector/DFBrowser_SearchView.hxx>
#include <inspector/DFBrowser_Window.hxx>

#include <inspector/ViewControl_Tools.hxx>

#include <TDF_Attribute.hxx>

#include <Standard_WarningsDisable.hxx>
#include <QItemSelectionModel>
#include <QMap>
#include <QStackedWidget>
#include <Standard_WarningsRestore.hxx>

// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
DFBrowser_AttributePaneStack::DFBrowser_AttributePaneStack(QObject* theParent)
    : QObject(theParent),
      myCurrentPane(0),
      myAttributesStack(0),
      myModule(0),
      myTreeLevelView(0),
      mySearchView(0),
      myEmptyWidget(0),
      myPaneMode(DFBrowser_AttributePaneType_ItemView)
{
  myPaneSelector = new DFBrowserPane_AttributePaneSelector(theParent);
}

// =======================================================================
// function : CreateWidget
// purpose :
// =======================================================================
void DFBrowser_AttributePaneStack::CreateWidget(QWidget* theParent)
{
  myAttributesStack = new QStackedWidget(theParent);
  ViewControl_Tools::SetWhiteBackground(myAttributesStack);
  myEmptyWidget = new QWidget(theParent);
  ViewControl_Tools::SetWhiteBackground(myEmptyWidget);

  myAttributesStack->addWidget(myEmptyWidget);

  myTreeLevelView = new DFBrowser_TreeLevelView(theParent);
  myAttributesStack->addWidget(myTreeLevelView->GetControl());

  mySearchView = new DFBrowser_SearchView(theParent);
  myAttributesStack->addWidget(mySearchView->GetControl());

  myAttributesStack->setCurrentWidget(myEmptyWidget);
}

// =======================================================================
// function : SetPaneMode
// purpose :
// =======================================================================
void DFBrowser_AttributePaneStack::SetPaneMode(const DFBrowser_AttributePaneType& theMode)
{
  if (myPaneMode == theMode)
    return;

  myPaneMode = theMode;
  if (myPaneMode == DFBrowser_AttributePaneType_SearchView)
  {
    // clear highlight in tree model
    DFBrowser_TreeModel* aModel = dynamic_cast<DFBrowser_TreeModel*>(myModule->GetOCAFViewModel());
    if (aModel && aModel->HasHighlighted())
      aModel->SetHighlighted(QModelIndexList());
    myAttributesStack->setCurrentWidget(mySearchView->GetControl());
  }
  else
  {
    QItemSelectionModel* aSelectionModel = myModule->GetOCAFViewSelectionModel();
    QModelIndex          anIndex =
      TreeModel_ModelBase::SingleSelected(aSelectionModel->selectedIndexes(), 0);
    SetCurrentItem(anIndex);
  }
}

// =======================================================================
// function : SetCurrentItem
// purpose :
// =======================================================================
void DFBrowser_AttributePaneStack::SetCurrentItem(const QModelIndex& theIndex)
{
  if (myPaneMode != DFBrowser_AttributePaneType_ItemView)
    return;

  // clear highlight in tree model
  DFBrowser_TreeModel* aModel = dynamic_cast<DFBrowser_TreeModel*>(myModule->GetOCAFViewModel());
  if (aModel && aModel->HasHighlighted())
    aModel->SetHighlighted(QModelIndexList());

  myCurrentPane                    = 0;
  QWidget*              aWidget    = 0;
  TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(theIndex);
  if (!anItemBase)
    return;

  if (DFBrowser_TreeLevelView::ProcessItem(theIndex))
    aWidget = myTreeLevelView->GetControl();
  else
  {
    DFBrowser_ItemPtr anItem = itemDynamicCast<DFBrowser_Item>(anItemBase);
    if (!anItem)
      return;

    if (myAttributesStack->currentWidget() == myTreeLevelView->GetControl())
      myTreeLevelView->ClearSelection();
    Handle(TDF_Attribute) anAttribute = anItem->GetAttribute();
    myCurrentPane                     = myModule->GetAttributePane(anAttribute);

    if (myCurrentPane)
    {
      aWidget = myCurrentPane->GetWidget(myAttributesStack, true);
      if (aWidget)
      {
        int aWidgetIndex = myAttributesStack->indexOf(aWidget);
        if (aWidgetIndex < 0)
          myAttributesStack->addWidget(aWidget);
      }
      myCurrentPane->Init(anAttribute);

      std::list<QItemSelectionModel*> aSelectionModels = myCurrentPane->GetSelectionModels();
      myPaneSelector->SetCurrentSelectionModels(aSelectionModels);
    }
  }
  myAttributesStack->setCurrentWidget(aWidget != NULL ? aWidget : myEmptyWidget);
}