/////////////////////////////////////////////////////////////////////////////// // Called when the "New Layer" button is clicked on the toolbar. Creates an // un-doable command that adds a layer to the scene (thereby adding it to this // control). // void LayersPanel::OnNewLayer( wxCommandEvent& event ) { if ( m_Scene ) { LayerPtr layer = new Layer(); layer->SetOwner( m_Scene ); m_Scene->Push( new SceneNodeExistenceCommand( Undo::ExistenceActions::Add, m_Scene, layer ) ); m_Scene->Execute( false ); } }
/////////////////////////////////////////////////////////////////////////////// // Called when the "New Layer From Selection" button is clicked on the toolbar. // void LayersPanel::OnNewLayerFromSelection( wxCommandEvent& dummyEvt ) { if ( m_Scene ) { if(IsSelectionValid() == false) { return; } BatchUndoCommandPtr batch = new BatchUndoCommand (); LayerPtr layer = new Layer(); layer->SetOwner( m_Scene ); layer->Initialize(); // Generate a name for this layer GenerateLayerName(layer); batch->Push( new SceneNodeExistenceCommand( ExistenceActions::Add, m_Scene, layer ) ); // Step 2: add all the selected items to the layer const OS_ObjectDumbPtr& selection = m_Scene->GetSelection().GetItems(); OS_ObjectDumbPtr::Iterator itr = selection.Begin(); OS_ObjectDumbPtr::Iterator end = selection.End(); for ( ; itr != end; ++itr ) { //If the element is a supported type if( *itr ) { SceneNode* node = Reflect::SafeCast< SceneNode >( *itr ); if ( node ) { batch->Push( new DependencyCommand( DependencyCommand::Connect, layer, node ) ); } } } m_Scene->Push( batch ); m_Scene->Execute( false ); } }