2
2
*
3
3
MIT License
4
4
5
- Copyright (c) 2017 Fabian Gerold
5
+ Copyright (c) 2024 Fabian Gerold
6
6
7
7
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
8
8
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
36
36
#include " cmd/CommandManager.h"
37
37
#include " IncludeGeometryHeaders.h"
38
38
#include " IfcPlusPlusSystem.h"
39
+ #include " viewer/IntersectionHandler.h"
39
40
#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"
55
44
56
45
IfcPlusPlusSystem::IfcPlusPlusSystem ()
57
46
{
58
47
m_command_manager = shared_ptr<CommandManager>( new CommandManager () );
59
48
m_ifc_model = shared_ptr<BuildingModel>( new BuildingModel () );
60
49
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 );
81
54
}
82
55
83
56
IfcPlusPlusSystem::~IfcPlusPlusSystem (){}
@@ -87,11 +60,6 @@ void IfcPlusPlusSystem::setIfcModel( shared_ptr<BuildingModel>& model )
87
60
m_ifc_model = model;
88
61
}
89
62
90
- void IfcPlusPlusSystem::setRootNode ( osg::Group* root )
91
- {
92
- m_rootnode = root;
93
- }
94
-
95
63
bool IfcPlusPlusSystem::handle (const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa*/ )
96
64
{
97
65
bool handled=false ;
@@ -143,6 +111,11 @@ bool IfcPlusPlusSystem::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActio
143
111
return handled;
144
112
}
145
113
114
+ void IfcPlusPlusSystem::setCtrlKeyDown (bool ctrl_key_down)
115
+ {
116
+ m_control_key_down = ctrl_key_down;
117
+ }
118
+
146
119
#ifdef _DEBUG
147
120
#define _DEBUG_GEOMETRY
148
121
#endif
@@ -191,7 +164,7 @@ void IfcPlusPlusSystem::setObjectSelected( shared_ptr<BuildingEntity> ifc_object
191
164
const std::string guid = getGUID (ifc_object);
192
165
if ( !grp )
193
166
{
194
- grp = findNodeByIfcId ( m_sw_model , guid );
167
+ grp = findNodeByIfcId ( m_view_controller-> getModelNode () , guid);
195
168
}
196
169
197
170
if ( selected )
@@ -221,19 +194,7 @@ void IfcPlusPlusSystem::setObjectSelected( shared_ptr<BuildingEntity> ifc_object
221
194
222
195
if ( select_child )
223
196
{
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 ());
237
198
}
238
199
239
200
std::unordered_map<std::string, shared_ptr<BuildingEntity> > map_objects;
@@ -250,20 +211,7 @@ void IfcPlusPlusSystem::setObjectSelected( shared_ptr<BuildingEntity> ifc_object
250
211
if ( it_selected != m_map_selected.end () )
251
212
{
252
213
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 ();
267
215
m_map_selected.erase ( it_selected );
268
216
}
269
217
}
@@ -279,19 +227,7 @@ void IfcPlusPlusSystem::clearSelection()
279
227
{
280
228
shared_ptr<SelectedEntity>& selected_entity = (*it).second ;
281
229
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 ();
295
231
}
296
232
m_map_selected.clear ();
297
233
}
@@ -311,76 +247,7 @@ void IfcPlusPlusSystem::notifyModelLoadingDone()
311
247
emit ( signalModelLoadingDone () );
312
248
}
313
249
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)
358
251
{
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));
386
253
}
0 commit comments