3 * Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * See the file ./license.txt
25 \date September 2006 - January 2007
26 \brief CMSCOPE is a typical scope which links its input to the simulation time
27 \see CMSCOPE.sci in macros/scicos_blocks/Sinks/
29 #include "CurrentObjectsManagement.h"
30 #include "scoMemoryScope.h"
31 #include "scoWindowScope.h"
33 #include "scoGetProperty.h"
34 #include "scoSetProperty.h"
35 #include "scicos_block4.h"
37 /** \fn cmscope_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
38 \brief Function to draw or redraw the window
40 void cmscope_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
43 int * ipar; //Integer Parameters
44 int * colors; //Colors
45 int win; //Windows ID : To give a name to the window
46 int buffer_size; //Buffer Size
47 int win_pos[2]; //Position of the Window
48 int win_dim[2]; //Dimension of the Window
52 double * rpar; //Reals parameters
54 double * period; //Refresh Period of the scope is a vector here
55 double * ymin,* ymax; //Ymin and Ymax are vectors here
58 int * number_of_curves_by_subwin;
63 rpar = GetRparPtrs(block);
64 ipar = GetIparPtrs(block);
65 nipar = GetNipar(block);
67 number_of_subwin = ipar[1];
68 buffer_size = ipar[2];
74 //Don't forget malloc for 'type *'
75 number_of_curves_by_subwin = (int*)scicos_malloc(number_of_subwin*sizeof(int));
76 for (i = 7; i < 7+number_of_subwin ; i++)
78 number_of_curves_by_subwin[i-7] = ipar[i];
79 nbr_total_curves = nbr_total_curves + ipar[i];
81 colors = (int*)scicos_malloc(nbr_total_curves*sizeof(int));
82 for(i = 0; i < nbr_total_curves ; i++)
84 colors[i] = ipar[i+7+number_of_subwin];
86 inherited_events = ipar[7+number_of_subwin+number_of_subwin];
91 period = (double*)scicos_malloc(number_of_subwin*sizeof(double));
92 for (i = 0 ; i < number_of_subwin ; i++)
94 period[i] = rpar[i+1];
97 ymin = (double*)scicos_malloc(number_of_subwin*sizeof(double));
98 ymax = (double*)scicos_malloc(number_of_subwin*sizeof(double));
99 for (i = 0 ; i < number_of_subwin ; i++)
101 ymin[i] = rpar[2*i+nbr_period+1];
102 ymax[i] = rpar[2*i+nbr_period+2];
105 /*Allocating memory*/
109 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, number_of_curves_by_subwin);
110 for(i = 0 ; i < number_of_subwin ; i++)
112 scoSetLongDrawSize(*pScopeMemory, i, 5000);
113 scoSetShortDrawSize(*pScopeMemory,i,buffer_size);
114 scoSetPeriod(*pScopeMemory,i,period[i]);
118 /* Xmin and Xmax are calculated here because we need a variable which is only existing in the pScopeMemory. pScopeMemory is allocated just few lines before. Indeed in this TimeAmplitudeScope Xmin and Xmax have to change often. To be sure to redraw in the correct scale we have to calculate xmin and xmax thanks to the period_counter. If the window haven't to be redraw (recreate) it wouldn't be necessary*/
119 xmin = (double*)scicos_malloc(number_of_subwin*sizeof(double));
120 xmax = (double*)scicos_malloc(number_of_subwin*sizeof(double));
121 for (i = 0 ; i < number_of_subwin ; i++)
123 xmin[i] = period[i]*(scoGetPeriodCounter(*pScopeMemory,i));
124 xmax[i] = period[i]*(scoGetPeriodCounter(*pScopeMemory,i)+1);
127 /*Creating the Scope*/
128 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, xmin, xmax, ymin, ymax, NULL, NULL);
129 if(scoGetScopeActivation(*pScopeMemory) == 1)
131 scoAddTitlesScope(*pScopeMemory,"t","y",NULL);
133 /*Add a couple of polyline : one for the shortdraw and one for the longdraw*/
134 /* scoAddPolylineLineStyle(*pScopeMemory,colors); */
135 scoAddCoupleOfPolylines(*pScopeMemory,colors);
137 scicos_free(number_of_curves_by_subwin);
146 /** \fn void cmscope(scicos_block * block, int flag)
147 \brief the computational function
148 \param block A pointer to a scicos_block
149 \param flag An integer which indicates the state of the block (init, update, ending)
151 void cmscope(scicos_block * block, int flag)
154 ScopeMemory * pScopeMemory;
157 double t; //get_scicos_time()
158 scoGraphicalObject pShortDraw;
162 /* Initializations and Allocations*/
163 //Allocations are done here because there are dependent of some values presents below
165 /* State Machine Control */
170 cmscope_draw(block,&pScopeMemory,1);
171 break; //Break of the switch condition don t forget it
172 } //End of Initialization
176 /*Retreiving Scope in the block->work*/
177 scoRetrieveScopeMemory(block->work,&pScopeMemory);
178 if(scoGetScopeActivation(pScopeMemory) == 1)
180 /* Charging Elements */
181 t = get_scicos_time();
182 /* If window has been destroyed we recreate it */
183 if(scoGetPointerScopeWindow(pScopeMemory) == NULL)
185 cmscope_draw(block,&pScopeMemory,0);
188 scoRefreshDataBoundsX(pScopeMemory,t);
190 //Here we are calculating the points in the polylines
191 for (i = 0 ; i < scoGetNumberOfSubwin(pScopeMemory) ; i++)
193 u1 = GetRealInPortPtrs(block,i+1);
194 pShortDraw = scoGetPointerShortDraw(pScopeMemory,i,0);
195 NbrPtsShort = pPOLYLINE_FEATURE(pShortDraw)->n1;
196 for (j = 0; j < scoGetNumberOfCurvesBySubwin(pScopeMemory,i) ; j++)
198 pShortDraw = scoGetPointerShortDraw(pScopeMemory,i,j);
199 pPOLYLINE_FEATURE(pShortDraw)->pvx[NbrPtsShort] = t;
200 pPOLYLINE_FEATURE(pShortDraw)->pvy[NbrPtsShort] = u1[j];
201 pPOLYLINE_FEATURE(pShortDraw)->n1++;
205 scoDrawScopeAmplitudeTimeStyle(pScopeMemory, t);
208 //Break of the switch don t forget it !
209 }//End of stateupdate
211 //This case is activated when the simulation is done or when we close scicos
215 scoRetrieveScopeMemory(block->work, &pScopeMemory);
216 if(scoGetScopeActivation(pScopeMemory) == 1)
218 sciSetUsedWindow(scoGetWindowID(pScopeMemory));
219 pShortDraw = sciGetCurrentFigure();
220 pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
221 pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
222 scoDelCoupleOfPolylines(pScopeMemory);
225 scoFreeScopeMemory(block->work, &pScopeMemory);