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 CMATVIEW is a scope that connects a matrix to a grayplot. The values of the matrix are the values at the nodes
27 \see CMATVIEW.sci in macros/scicos_blocks/Sinks/
29 #include "CurrentObjectsManagement.h"
30 #include "DrawingBridge.h"
31 #include "scoMemoryScope.h"
32 #include "scoWindowScope.h"
34 #include "scoGetProperty.h"
35 #include "scoSetProperty.h"
36 #include "scicos_block4.h"
40 /** \fn cmatview_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
41 \brief Function to draw or redraw the window
43 void cmatview_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
46 int * ipar; //Integer Parameters
47 int win_pos[2]; //Position of the Window
48 int win_dim[2]; //Dimension of the Window
50 double * rpar; //Reals parameters
51 double ymin, ymax; //Ymin and Ymax are vectors here
53 int number_of_curves_by_subwin;
58 rpar = GetRparPtrs(block);
59 ipar = GetIparPtrs(block);
67 mat = (double*)scicos_malloc(size_mat*sizeof(double));
68 for(i = 0 ; i < size_mat ; i++)
72 xmax = GetInPortSize(block,1,1);
74 ymax = GetInPortSize(block,1,2);
77 number_of_curves_by_subwin = 1;
83 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
86 /*Creating the Scope*/
87 scoInitOfWindow(*pScopeMemory, dimension, -1, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
88 if(scoGetScopeActivation(*pScopeMemory) == 1)
90 sciSetColormap(scoGetPointerScopeWindow(*pScopeMemory), mat , size_mat/3, 3);
91 scoAddTitlesScope(*pScopeMemory,"x","y",NULL);
92 scoAddGrayplotForShortDraw(*pScopeMemory,0,0,GetInPortSize(block,1,1),GetInPortSize(block,1,2));
98 /** \fn void cmatview(scicos_block * block, int flag)
99 \brief the computational function
100 \param block A pointer to a scicos_block
101 \param flag An int which indicates the state of the block (init, update, ending)
103 void cmatview(scicos_block * block, int flag)
106 ScopeMemory * pScopeMemory;
107 scoGraphicalObject pShortDraw;
113 /* Initializations and Allocations*/
114 //Allocations are done here because there are dependent of some values presents below
116 /* State Machine Control */
121 cmatview_draw(block,&pScopeMemory,1);
126 /*Retreiving Scope in the block->work*/
127 scoRetrieveScopeMemory(block->work,&pScopeMemory);
128 if(scoGetScopeActivation(pScopeMemory) == 1)
130 /* If window has been destroyed we recreate it */
131 if(scoGetPointerScopeWindow(pScopeMemory) == NULL)
133 cmatview_draw(block,&pScopeMemory,0);
136 pShortDraw = scoGetPointerShortDraw(pScopeMemory,0,0);
137 rpar = GetRparPtrs(block);
140 u1 = GetInPortPtrs(block,1);
142 dim_i = GetInPortRows(block,1);
143 dim_j = GetInPortCols(block,1);
145 for(i = 0 ; i < dim_i ; i++)
147 for(j = 0; j < dim_j ; j++)
149 pGRAYPLOT_FEATURE(pShortDraw)->pvecz[i*dim_j+j] = floor(alpha*u1[j+i*dim_j]+beta);
152 sciSetUsedWindow(scoGetWindowID(pScopeMemory));
153 if(sciGetPixmapMode(scoGetPointerScopeWindow(pScopeMemory)))
155 /* TODO : not implemented */
156 /*C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);*/
158 sciDrawObj(scoGetPointerShortDraw(pScopeMemory,0,0));
161 }//End of stateupdate
164 scoRetrieveScopeMemory(block->work, &pScopeMemory);
165 if(scoGetScopeActivation(pScopeMemory) == 1)
167 /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
168 /*pShortDraw = sciGetCurrentFigure(); */
169 /*pFIGURE_FEATURE(pShortDraw)->user_data = NULL; */
170 /*pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0; */
171 /* Check if figure is still opened, otherwise, don't try to destroy it again. */
172 scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
175 /*pShortDraw = scoGetPointerScopeWindow(pScopeMemory);*/
176 clearUserData(figure);
179 scoFreeScopeMemory(block->work, &pScopeMemory);