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 CSCOPE is a typical scope which links its input to the simulation time but there is only one input instead of CMSCOPE
27 \see CSCOPE.sci in macros/scicos_blocks/Sinks/
30 #include "scoMemoryScope.h"
31 #include "scoWindowScope.h"
33 #include "scoGetProperty.h"
34 #include "scoSetProperty.h"
35 #include "scicos_block4.h"
37 /** \fn cscope_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
38 \brief Function to draw or redraw the window
40 void cscope_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
47 double ymin, ymax, xmin, xmax;
53 int number_of_curves_by_subwin[1];
56 /*Retrieving Parameters*/
57 rpar = GetRparPtrs(block);
58 ipar = GetIparPtrs(block);
59 nipar = GetNipar(block);
60 buffer_size = ipar[2];
63 win_pos[0] = ipar[(nipar-1) - 3];
64 win_pos[1] = ipar[(nipar-1) - 2];
65 win_dim[0] = ipar[(nipar-1) - 1];
66 win_dim[1] = ipar[nipar-1];
68 number_of_curves_by_subwin[0] = GetInPortRows(block,1);
75 colors = (int*)scicos_malloc(number_of_curves_by_subwin[0]*sizeof(int));
76 for(i = 0 ; i < number_of_curves_by_subwin[0] ; i++)
78 colors[i] = ipar[3+i];
84 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, number_of_curves_by_subwin);
85 /*Must be placed before adding polyline or other elements*/
86 scoSetLongDrawSize(*pScopeMemory, 0, 50);
87 scoSetShortDrawSize(*pScopeMemory,0,buffer_size);
88 scoSetPeriod(*pScopeMemory,0,period);
91 xmin = period*scoGetPeriodCounter(*pScopeMemory,0);
92 xmax = period*(scoGetPeriodCounter(*pScopeMemory,0)+1);
94 /*Creating the Scope*/
95 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
96 if(scoGetScopeActivation(*pScopeMemory) == 1)
98 scoAddTitlesScope(*pScopeMemory,"t","y",NULL);
99 /*Add a couple of polyline : one for the shortdraw and one for the longdraw*/
100 scoAddCoupleOfPolylines(*pScopeMemory,colors);
101 /* scoAddPolylineLineStyle(*pScopeMemory,colors); */
106 /** \fn void cscope(scicos_block * block,int flag)
107 \brief the computational function
108 \param block A pointer to a scicos_block
109 \param flag An integer which indicates the state of the block (init, update, ending)
111 void cscope(scicos_block * block,int flag)
113 ScopeMemory * pScopeMemory;
118 scoGraphicalObject pShortDraw;
123 cscope_draw(block,&pScopeMemory,1);
128 scoRetrieveScopeMemory(block->work,&pScopeMemory);
129 if(scoGetScopeActivation(pScopeMemory) == 1)
131 t = get_scicos_time();
132 /*Retreiving Scope in the block->work*/
134 /*If window has been destroyed we recreate it*/
135 if(scoGetPointerScopeWindow(pScopeMemory) == NULL)
137 cscope_draw(block,&pScopeMemory,0);
139 /*Maybe we are in the end of axes so we have to draw new ones */
140 scoRefreshDataBoundsX(pScopeMemory,t);
142 //Cannot be factorized depends of the scope
143 u1 = GetRealInPortPtrs(block,1);
144 for (i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
146 pShortDraw = scoGetPointerShortDraw(pScopeMemory,0,i);
147 NbrPtsShort = pPOLYLINE_FEATURE(pShortDraw)->n1;
148 pPOLYLINE_FEATURE(pShortDraw)->pvx[NbrPtsShort] = t;
149 pPOLYLINE_FEATURE(pShortDraw)->pvy[NbrPtsShort] = u1[i];
150 pPOLYLINE_FEATURE(pShortDraw)->n1++;
155 scoDrawScopeAmplitudeTimeStyle(pScopeMemory, t);
161 scoRetrieveScopeMemory(block->work, &pScopeMemory);
162 if(scoGetScopeActivation(pScopeMemory) == 1)
164 sciSetUsedWindow(scoGetWindowID(pScopeMemory));
165 pShortDraw = sciGetCurrentFigure();
166 pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
167 pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
168 scoDelCoupleOfPolylines(pScopeMemory);
170 scoFreeScopeMemory(block->work, &pScopeMemory);