Skip to content

Commit b04e650

Browse files
author
Davide Faconti
committed
Working on custom ndoes and ports
1 parent 3073ea5 commit b04e650

File tree

7 files changed

+64
-15
lines changed

7 files changed

+64
-15
lines changed

bt_editor/XML_utilities.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ NodeModel buildTreeNodeModelFromXML(const QDomElement& node)
6262
{
6363
port_model.type_name = port_element.attribute("type");
6464
}
65+
if( port_element.hasAttribute("default") )
66+
{
67+
port_model.default_value = port_element.attribute("default");
68+
}
6569

6670
if( port_element.hasAttribute("name") )
6771
{

bt_editor/bt_editor_base.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,6 @@ PortModel &PortModel::operator =(const BT::PortInfo &src)
218218
this->direction = src.direction();
219219
this->description = QString::fromStdString(src.description());
220220
this->type_name = QString::fromStdString(BT::demangle(src.type()));
221+
this->default_value = QString::fromStdString( src.defaultValue());
221222
return *this;
222223
}

bt_editor/graphic_container.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,17 @@ void GraphicContainer::nodeReorder()
165165
void GraphicContainer::zoomHomeView()
166166
{
167167
QRectF rect = _scene->itemsBoundingRect();
168+
rect.setBottom( rect.top() + rect.height()* 1.2 );
169+
170+
const int min_height = 300;
171+
if( rect.height() < min_height )
172+
{
173+
rect.setBottom( rect.top() + min_height );
174+
}
175+
168176
_view->setSceneRect (rect);
169177
_view->fitInView(rect, Qt::KeepAspectRatio);
170-
_view->scale(0.7, 0.7);
178+
_view->scale(0.9, 0.9);
171179
}
172180

173181
bool GraphicContainer::containsValidTree() const

bt_editor/mainwindow.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ using QtNodes::FlowScene;
3838
using QtNodes::NodeGraphicsObject;
3939
using QtNodes::NodeState;
4040

41-
4241
MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) :
4342
QMainWindow(parent),
4443
ui(new Ui::MainWindow),
@@ -119,9 +118,6 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) :
119118
ui->splitter->setStretchFactor(0, 1);
120119
ui->splitter->setStretchFactor(1, 4);
121120

122-
createTab("BehaviorTree");
123-
onTabSetMainTree(0);
124-
125121
QShortcut* undo_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z), this);
126122
connect( undo_shortcut, &QShortcut::activated, this, &MainWindow::onUndoInvoked );
127123

@@ -160,12 +156,22 @@ MainWindow::MainWindow(GraphicMode initial_mode, QWidget *parent) :
160156
connect( _monitor_widget, &SidepanelMonitor::loadBehaviorTree,
161157
this, &MainWindow::onCreateAbsBehaviorTree );
162158
#endif
163-
onSceneChanged();
164159

165160
ui->tabWidget->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
166161
connect( ui->tabWidget->tabBar(), &QTabBar::customContextMenuRequested,
167162
this, &MainWindow::onTabCustomContextMenuRequested);
163+
}
168164

165+
void MainWindow::showEvent( QShowEvent* )
166+
{
167+
init();
168+
}
169+
170+
void MainWindow::init()
171+
{
172+
createTab("BehaviorTree");
173+
onTabSetMainTree(0);
174+
onSceneChanged();
169175
_current_state = saveCurrentState();
170176
}
171177

@@ -204,11 +210,7 @@ GraphicContainer* MainWindow::createTab(const QString &name)
204210
ui->tabWidget->addTab( ti->view(), name );
205211

206212
ti->scene()->createNodeAtPos( "Root", "Root", QPointF(-30,-30) );
207-
208-
QRectF rect( QPointF(-20, -20), QPointF(20, 20) );
209-
ti->view()->setSceneRect (rect);
210-
ti->view()->fitInView(rect, Qt::KeepAspectRatio);
211-
ti->view()->setTransform(QTransform(1.5, 0, 0, 1.5, 0, 0));
213+
ti->zoomHomeView();
212214

213215
//--------------------------------
214216

@@ -227,8 +229,6 @@ GraphicContainer* MainWindow::createTab(const QString &name)
227229
connect( ti, &GraphicContainer::addNewModel,
228230
this, &MainWindow::onAddToModelRegistry);
229231

230-
//--------------------------------
231-
232232
return ti;
233233
}
234234

@@ -470,7 +470,14 @@ QString MainWindow::saveToXML() const
470470
}
471471

472472
port_element.setAttribute("name", port_name );
473-
port_element.setAttribute("type", port.type_name );
473+
if( port.type_name.isEmpty() == false)
474+
{
475+
port_element.setAttribute("type", port.type_name );
476+
}
477+
if( port.default_value.isEmpty() == false)
478+
{
479+
port_element.setAttribute("default", port.default_value );
480+
}
474481

475482
if( !port.description.isEmpty() )
476483
{

bt_editor/mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ private slots:
126126

127127
private:
128128

129+
void showEvent(QShowEvent*) override;
130+
131+
void init();
132+
129133
void updateCurrentMode();
130134

131135
void lockEditing(const bool locked);

test_data/custom_ports.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<root main_tree_to_execute="BehaviorTree">
2+
<!-- ////////// -->
3+
<BehaviorTree ID="BehaviorTree">
4+
<Sequence>
5+
<Action input="42" ID="Action_A"/>
6+
<Condition result="69" ID="Condition_B"/>
7+
<SubTree ID="LotOfStuff" res="200" param="100"/>
8+
</Sequence>
9+
</BehaviorTree>
10+
<!-- ////////// -->
11+
<TreeNodesModel>
12+
<Action ID="Action_A">
13+
<input_port default="42" name="input">interesting</input_port>
14+
</Action>
15+
<Condition ID="Condition_B">
16+
<output_port default="69" name="result">Cool</output_port>
17+
</Condition>
18+
<SubTree ID="LotOfStuff">
19+
<input_port name="param"/>
20+
<output_port name="res"/>
21+
</SubTree>
22+
</TreeNodesModel>
23+
<!-- ////////// -->
24+
</root>
25+

0 commit comments

Comments
 (0)