001 /*--------------------------------------------------------------------------+ 002 $Id: StateflowBlock.java 26285 2010-02-18 11:22:54Z juergens $ 003 | | 004 | Copyright 2005-2010 Technische Universitaet Muenchen | 005 | | 006 | Licensed under the Apache License, Version 2.0 (the "License"); | 007 | you may not use this file except in compliance with the License. | 008 | You may obtain a copy of the License at | 009 | | 010 | http://www.apache.org/licenses/LICENSE-2.0 | 011 | | 012 | Unless required by applicable law or agreed to in writing, software | 013 | distributed under the License is distributed on an "AS IS" BASIS, | 014 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 015 | See the License for the specific language governing permissions and | 016 | limitations under the License. | 017 +--------------------------------------------------------------------------*/ 018 package edu.tum.cs.simulink.model.stateflow; 019 020 import edu.tum.cs.commons.clone.DeepCloneException; 021 import edu.tum.cs.simulink.model.SimulinkBlock; 022 023 /** 024 * A special Simulink block that stores state charts. There is a one-to-one 025 * association between {@link StateflowBlock}s and {@link StateflowChart}s. 026 * The sub blocks of this block are automatically generated by Simulink. 027 * 028 * 029 * @author deissenb 030 * @author $Author: juergens $ 031 * @version $Rev: 26285 $ 032 * @levd.rating GREEN Hash: 7599AD3B1F4D90C2C8538BFEE18AEECC 033 */ 034 public class StateflowBlock extends SimulinkBlock { 035 036 /** The chart that belongs to this block. */ 037 private StateflowChart chart; 038 039 /** 040 * Create Stateflow block. 041 * 042 * @param chart 043 * The chart that belongs to this block. 044 */ 045 public StateflowBlock(StateflowChart chart) { 046 this.chart = chart; 047 chart.setStateflowBlock(this); 048 } 049 050 /** Create new Stateflow block from existing block (for deep cloning). */ 051 private StateflowBlock(StateflowBlock block) throws DeepCloneException { 052 super(block); 053 chart = block.chart.deepClone(); 054 chart.setStateflowBlock(this); 055 } 056 057 /** Get the Stateflow chart that belongs to this block. */ 058 public StateflowChart getChart() { 059 return chart; 060 } 061 062 /** Unlinks this object from the simulink tree. */ 063 @Override 064 public void remove() { 065 chart.getMachine().removeChart(chart); 066 chart = null; 067 super.remove(); 068 } 069 070 /** Deep clone this block. */ 071 @Override 072 public StateflowBlock deepClone() throws DeepCloneException { 073 return new StateflowBlock(this); 074 } 075 }