Skip to content

Commit 6df518d

Browse files
committed
Improve navigation in 3D example viewer
1 parent a88f27f commit 6df518d

33 files changed

+4399
-1315
lines changed

examples/SimpleViewerExampleQt/Resources/styles.css

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ QFrame {
66
QWidget#OpenFileWidget { background-color: rgba(240,240,240,0.5); border: 1px solid #cecece; margin: 10px;}
77
QWidget#SettingsWidget { background-color: rgba(240,240,240,0.5); border: 1px solid #cecece; margin: 10px;}
88

9+
QStatusBar { height:20px;max-height: 24px;}
10+
911
QTextEdit
1012
{
1113
border: 1px solid #cecece;

examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj

+9-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
<DisableSpecificWarnings>4305;4005</DisableSpecificWarnings>
256256
</ClCompile>
257257
<Link>
258-
<SubSystem>Console</SubSystem>
258+
<SubSystem>Windows</SubSystem>
259259
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
260260
<AdditionalLibraryDirectories>..\..\IfcPlusPlus\bin;$(OSG_DIR)\lib;$(OSG_DIR)\build\lib;$(FREETYPE_DIR)\objs\vc2010\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
261261
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -299,7 +299,10 @@
299299
<ClCompile Include="src\IfcPlusPlusSystem.cpp" />
300300
<ClCompile Include="src\main.cpp" />
301301
<ClCompile Include="src\viewer\GraphicsWindowQt.cpp" />
302-
<ClCompile Include="src\viewer\OrbitCameraManipulator.cpp" />
302+
<ClCompile Include="src\viewer\IntersectionHandler.cpp" />
303+
<ClCompile Include="src\viewer\Orbit3DManipulator.cpp" />
304+
<ClCompile Include="src\viewer\ViewController.cpp" />
305+
<ClCompile Include="src\viewer\ViewerUtil.cpp" />
303306
<ClCompile Include="src\viewer\ViewerWidget.cpp" />
304307
</ItemGroup>
305308
<ItemGroup>
@@ -356,6 +359,8 @@
356359
<ClInclude Include="src\cmd\CmdRemoveSelectedObjects.h" />
357360
<ClInclude Include="src\cmd\Command.h" />
358361
<ClInclude Include="src\cmd\CommandManager.h" />
362+
<ClInclude Include="src\viewer\ViewController.h" />
363+
<ClInclude Include="src\viewer\ViewerUtil.h" />
359364
<QtMoc Include="src\viewer\ViewerWidget.h">
360365
</QtMoc>
361366
<QtMoc Include="src\IfcPlusPlusSystem.h">
@@ -374,7 +379,8 @@
374379
<ClInclude Include="src\gui\ScopedLockAndBlock.h" />
375380
<ClInclude Include="src\IncludeGeometryHeaders.h" />
376381
<ClInclude Include="src\viewer\GraphicsWindowQt.h" />
377-
<ClInclude Include="src\viewer\OrbitCameraManipulator.h" />
382+
<ClInclude Include="src\viewer\IntersectionHandler.h" />
383+
<QtMoc Include="src\viewer\Orbit3DManipulator.h" />
378384
</ItemGroup>
379385
<ItemGroup>
380386
<ResourceCompile Include="Resources\appicon.rc" />

examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj.filters

+24-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
<ClCompile Include="src\viewer\GraphicsWindowQt.cpp">
4848
<Filter>Source Dateien</Filter>
4949
</ClCompile>
50-
<ClCompile Include="src\viewer\OrbitCameraManipulator.cpp">
51-
<Filter>Source Dateien</Filter>
52-
</ClCompile>
5350
<ClCompile Include="src\IfcPlusPlusSystem.cpp">
5451
<Filter>Source Dateien</Filter>
5552
</ClCompile>
@@ -77,6 +74,18 @@
7774
<ClCompile Include="src\gui\EntityAttributeWidget.cpp">
7875
<Filter>Source Dateien</Filter>
7976
</ClCompile>
77+
<ClCompile Include="src\viewer\IntersectionHandler.cpp">
78+
<Filter>Source Dateien</Filter>
79+
</ClCompile>
80+
<ClCompile Include="src\viewer\Orbit3DManipulator.cpp">
81+
<Filter>Source Dateien</Filter>
82+
</ClCompile>
83+
<ClCompile Include="src\viewer\ViewerUtil.cpp">
84+
<Filter>Source Dateien</Filter>
85+
</ClCompile>
86+
<ClCompile Include="src\viewer\ViewController.cpp">
87+
<Filter>Source Dateien</Filter>
88+
</ClCompile>
8089
</ItemGroup>
8190
<ItemGroup>
8291
<QtRcc Include="Resources\ifcplusplus.qrc">
@@ -141,19 +150,28 @@
141150
<ClInclude Include="src\viewer\GraphicsWindowQt.h">
142151
<Filter>Header Dateien</Filter>
143152
</ClInclude>
144-
<ClInclude Include="src\viewer\OrbitCameraManipulator.h">
145-
<Filter>Header Dateien</Filter>
146-
</ClInclude>
147153
<ClInclude Include="src\IncludeGeometryHeaders.h">
148154
<Filter>Header Dateien</Filter>
149155
</ClInclude>
150156
<ClInclude Include="src\gui\ScopedLockAndBlock.h">
151157
<Filter>Header Dateien</Filter>
152158
</ClInclude>
159+
<ClInclude Include="src\viewer\ViewerUtil.h">
160+
<Filter>Header Dateien</Filter>
161+
</ClInclude>
162+
<ClInclude Include="src\viewer\ViewController.h">
163+
<Filter>Header Dateien</Filter>
164+
</ClInclude>
165+
<ClInclude Include="src\viewer\IntersectionHandler.h">
166+
<Filter>Header Dateien</Filter>
167+
</ClInclude>
153168
</ItemGroup>
154169
<ItemGroup>
155170
<QtMoc Include="src\gui\EntityAttributeWidget.h">
156171
<Filter>Header Dateien</Filter>
157172
</QtMoc>
173+
<QtMoc Include="src\viewer\Orbit3DManipulator.h">
174+
<Filter>Header Dateien</Filter>
175+
</QtMoc>
158176
</ItemGroup>
159177
</Project>

examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj.user

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
1919
</PropertyGroup>
2020
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
21-
<QtLastBackgroundBuild>2024-01-17T08:47:27.8852167Z</QtLastBackgroundBuild>
21+
<QtLastBackgroundBuild>2024-01-18T07:50:24.9045647Z</QtLastBackgroundBuild>
2222
</PropertyGroup>
2323
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
24-
<QtLastBackgroundBuild>2024-01-17T08:47:27.9653823Z</QtLastBackgroundBuild>
24+
<QtLastBackgroundBuild>2024-01-18T07:50:24.9860178Z</QtLastBackgroundBuild>
2525
</PropertyGroup>
2626
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
27-
<QtLastBackgroundBuild>2024-01-17T08:47:28.2838514Z</QtLastBackgroundBuild>
27+
<QtLastBackgroundBuild>2024-01-18T07:50:25.2048710Z</QtLastBackgroundBuild>
2828
</PropertyGroup>
2929
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
30-
<QtLastBackgroundBuild>2024-01-17T08:47:28.7635906Z</QtLastBackgroundBuild>
30+
<QtLastBackgroundBuild>2024-01-18T07:50:25.3122549Z</QtLastBackgroundBuild>
3131
</PropertyGroup>
3232
</Project>

examples/SimpleViewerExampleQt/src/IfcPlusPlusSystem.cpp

+20-153
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
MIT License
44
5-
Copyright (c) 2017 Fabian Gerold
5+
Copyright (c) 2024 Fabian Gerold
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
88
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -36,48 +36,21 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU
3636
#include "cmd/CommandManager.h"
3737
#include "IncludeGeometryHeaders.h"
3838
#include "IfcPlusPlusSystem.h"
39+
#include "viewer/IntersectionHandler.h"
3940
#include "viewer/ViewerWidget.h"
40-
#include "viewer/OrbitCameraManipulator.h"
41-
42-
std::string getGUID(const shared_ptr<BuildingEntity>& ent)
43-
{
44-
std::string guid;
45-
shared_ptr<IfcRoot> ifc_root = dynamic_pointer_cast<IfcRoot>(ent);
46-
if (ifc_root)
47-
{
48-
if (ifc_root->m_GlobalId)
49-
{
50-
guid = ifc_root->m_GlobalId->m_value;
51-
}
52-
}
53-
return guid;
54-
}
41+
#include "viewer/ViewController.h"
42+
#include "viewer/Orbit3DManipulator.h"
43+
#include "viewer/ViewerUtil.h"
5544

5645
IfcPlusPlusSystem::IfcPlusPlusSystem()
5746
{
5847
m_command_manager = shared_ptr<CommandManager>( new CommandManager() );
5948
m_ifc_model = shared_ptr<BuildingModel>( new BuildingModel() );
6049
m_geometry_converter = shared_ptr<GeometryConverter>( new GeometryConverter( m_ifc_model ) );
61-
62-
m_rootnode = new osg::Group();
63-
m_rootnode->setName( "m_rootnode" );
64-
65-
m_sw_model = new osg::Switch();
66-
m_sw_model->setName( "m_sw_model" );
67-
m_rootnode->addChild( m_sw_model.get() );
68-
69-
m_sw_coord_axes = new osg::Switch();
70-
m_sw_coord_axes->setName( "m_sw_coord_axes" );
71-
m_rootnode->addChild( m_sw_coord_axes.get() );
72-
73-
m_show_curve_representation = true;
74-
m_light_on = false;
75-
76-
m_material_selected = new osg::Material();
77-
m_material_selected->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4f( 0.2f, 0.98f, 0.2f, 0.5f ) );
78-
m_material_selected->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4f( 0.2f, 0.85f, 0.2f, 1.0f ) );
79-
m_material_selected->setShininess( osg::Material::FRONT_AND_BACK, 35.0 );
80-
m_material_selected->setColorMode( osg::Material::SPECULAR );
50+
IntersectionHandler* ih = new IntersectionHandler(this);
51+
Orbit3DManipulator* camera_manip = new Orbit3DManipulator(this, ih);
52+
m_view_controller = shared_ptr<ViewController>(new ViewController(camera_manip));
53+
m_view_controller->getRootNode()->addChild(ih->m_group_selected);
8154
}
8255

8356
IfcPlusPlusSystem::~IfcPlusPlusSystem(){}
@@ -87,11 +60,6 @@ void IfcPlusPlusSystem::setIfcModel( shared_ptr<BuildingModel>& model )
8760
m_ifc_model = model;
8861
}
8962

90-
void IfcPlusPlusSystem::setRootNode( osg::Group* root )
91-
{
92-
m_rootnode = root;
93-
}
94-
9563
bool IfcPlusPlusSystem::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /*aa*/)
9664
{
9765
bool handled=false;
@@ -143,6 +111,11 @@ bool IfcPlusPlusSystem::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActio
143111
return handled;
144112
}
145113

114+
void IfcPlusPlusSystem::setCtrlKeyDown(bool ctrl_key_down)
115+
{
116+
m_control_key_down = ctrl_key_down;
117+
}
118+
146119
#ifdef _DEBUG
147120
#define _DEBUG_GEOMETRY
148121
#endif
@@ -191,7 +164,7 @@ void IfcPlusPlusSystem::setObjectSelected( shared_ptr<BuildingEntity> ifc_object
191164
const std::string guid = getGUID(ifc_object);
192165
if( !grp )
193166
{
194-
grp = findNodeByIfcId( m_sw_model, guid );
167+
grp = findNodeByIfcId( m_view_controller->getModelNode(), guid);
195168
}
196169

197170
if( selected )
@@ -221,19 +194,7 @@ void IfcPlusPlusSystem::setObjectSelected( shared_ptr<BuildingEntity> ifc_object
221194

222195
if( select_child )
223196
{
224-
osg::ref_ptr<osg::StateSet> stateset = grp->getOrCreateStateSet();
225-
osg::Material* material_previous = (osg::Material*)stateset->getAttribute( osg::StateAttribute::MATERIAL );
226-
if( material_previous )
227-
{
228-
selected_entity->m_material_previous = material_previous;
229-
}
230-
231-
//stateset->setAttribute( m_material_selected, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
232-
233-
osg::ref_ptr<osg::StateSet> statesetSelected = new osg::StateSet();
234-
statesetSelected->setAttribute(m_material_selected, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
235-
grp->setStateSet(statesetSelected);
236-
selected_entity->m_material_selected = m_material_selected;
197+
selected_entity->setSelected(m_view_controller->getMaterialSelected());
237198
}
238199

239200
std::unordered_map<std::string, shared_ptr<BuildingEntity> > map_objects;
@@ -250,20 +211,7 @@ void IfcPlusPlusSystem::setObjectSelected( shared_ptr<BuildingEntity> ifc_object
250211
if( it_selected != m_map_selected.end() )
251212
{
252213
shared_ptr<SelectedEntity> selected_entity = it_selected->second;
253-
254-
if( selected_entity->m_osg_group )
255-
{
256-
osg::ref_ptr<osg::StateSet> stateset_selected_node = selected_entity->m_osg_group->getOrCreateStateSet();
257-
if( selected_entity->m_material_previous )
258-
{
259-
stateset_selected_node->setAttribute( selected_entity->m_material_previous, osg::StateAttribute::ON );
260-
}
261-
else if( selected_entity->m_material_selected )
262-
{
263-
stateset_selected_node->removeAttribute( selected_entity->m_material_selected );
264-
}
265-
}
266-
214+
selected_entity->setUnselected();
267215
m_map_selected.erase( it_selected );
268216
}
269217
}
@@ -279,19 +227,7 @@ void IfcPlusPlusSystem::clearSelection()
279227
{
280228
shared_ptr<SelectedEntity>& selected_entity = (*it).second;
281229
shared_ptr<BuildingEntity> entity = selected_entity->m_entity;
282-
283-
if( selected_entity->m_osg_group )
284-
{
285-
osg::ref_ptr<osg::StateSet> stateset_selected_node = selected_entity->m_osg_group->getOrCreateStateSet();
286-
if( selected_entity->m_material_previous )
287-
{
288-
stateset_selected_node->setAttribute( selected_entity->m_material_previous, osg::StateAttribute::ON );
289-
}
290-
else if( selected_entity->m_material_selected )
291-
{
292-
stateset_selected_node->removeAttribute( selected_entity->m_material_selected );
293-
}
294-
}
230+
selected_entity->setUnselected();
295231
}
296232
m_map_selected.clear();
297233
}
@@ -311,76 +247,7 @@ void IfcPlusPlusSystem::notifyModelLoadingDone()
311247
emit( signalModelLoadingDone() );
312248
}
313249

314-
void IfcPlusPlusSystem::toggleSceneLight()
315-
{
316-
osg::StateSet* stateset_root = m_rootnode->getOrCreateStateSet();
317-
318-
if( !m_transform_light.valid() )
319-
{
320-
osg::ref_ptr<osg::Group> light_group = new osg::Group();
321-
light_group->setName( "light_group" );
322-
double model_size = 100; // TODO: adjust when model is loaded
323-
324-
osg::ref_ptr<osg::Light> light6 = new osg::Light();
325-
light6->setLightNum( 6 );
326-
light6->setPosition( osg::Vec4( 0.0, 0.0, 0.0, 1.0f ) );
327-
light6->setAmbient( osg::Vec4( 0.5f, 0.53f, 0.57f, 0.4f ) );
328-
light6->setDiffuse( osg::Vec4( 0.5f, 0.53f, 0.57f, 0.4f ) );
329-
light6->setConstantAttenuation( 1.0f );
330-
light6->setLinearAttenuation( 2.0f/model_size );
331-
light6->setQuadraticAttenuation( 2.0f/(model_size*model_size) );
332-
333-
osg::ref_ptr<osg::LightSource> light_source6 = new osg::LightSource();
334-
light_source6->setLight( light6 );
335-
light_source6->setLocalStateSetModes( osg::StateAttribute::ON );
336-
light_source6->setStateSetModes( *stateset_root, osg::StateAttribute::ON );
337-
m_transform_light = new osg::MatrixTransform( osg::Matrix::translate( 5, 5, 50 ) );
338-
m_transform_light->addChild( light_source6 );
339-
340-
light_group->addChild( m_transform_light );
341-
m_rootnode->addChild( light_group );
342-
343-
m_light_on = false;
344-
}
345-
346-
m_light_on = !m_light_on;
347-
if( m_light_on )
348-
{
349-
stateset_root->setMode( GL_LIGHT6, osg::StateAttribute::ON );
350-
}
351-
else
352-
{
353-
stateset_root->setMode( GL_LIGHT6, osg::StateAttribute::OFF );
354-
}
355-
}
356-
357-
void IfcPlusPlusSystem::switchCurveRepresentation( osg::Group* grp, bool on_off )
250+
void IfcPlusPlusSystem::notifyCursorCoordinates(double x, double y, double z)
358251
{
359-
m_show_curve_representation = on_off;
360-
osg::Switch* grp_switch = dynamic_cast<osg::Switch*>( grp );
361-
if( grp_switch )
362-
{
363-
if( grp_switch->getName().compare( "CurveRepresentation" ) == 0 )
364-
{
365-
if( on_off )
366-
{
367-
grp_switch->setAllChildrenOn();
368-
}
369-
else
370-
{
371-
grp_switch->setAllChildrenOff();
372-
}
373-
}
374-
}
375-
376-
unsigned int num_children = grp->getNumChildren();
377-
for( unsigned int i=0; i<num_children; ++i)
378-
{
379-
osg::Node* child_node = grp->getChild(i);
380-
osg::Group* child_grp = dynamic_cast<osg::Group*>( child_node );
381-
if( child_grp )
382-
{
383-
switchCurveRepresentation( child_grp, on_off );
384-
}
385-
}
252+
emit(signalCursorCoordinates(x, y, z));
386253
}

0 commit comments

Comments
 (0)