2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
18 #include "ScilabView.hxx"
19 #include "CallGraphicController.hxx"
23 #include "createGraphicObject.h"
24 #include "setGraphicObjectProperty.h"
25 #include "getGraphicObjectProperty.h"
26 #include "graphicObjectProperties.h"
27 #include "getScilabJavaVM.h"
28 #include "deleteGraphicObject.h"
32 * C Wrapping functions
35 void ScilabNativeView__createObject(char const* pstId)
37 ScilabView::createObject(pstId);
40 void ScilabNativeView__deleteObject(char const*pstId)
42 ScilabView::deleteObject(pstId);
45 void ScilabNativeView__updateObject(char const* pstId, int iProperty)
47 ScilabView::updateObject(pstId, iProperty);
50 void ScilabNativeView__setCurrentFigure(char const* pstId)
52 ScilabView::setCurrentFigure(pstId);
55 void ScilabNativeView__setCurrentSubWin(char const* pstId)
57 ScilabView::setCurrentSubWin(pstId);
60 void ScilabNativeView__setCurrentObject(char const* pstId)
62 ScilabView::setCurrentObject(pstId);
65 int ScilabNativeView__getValidDefaultFigureId()
67 return ScilabView::getValidDefaultFigureId();
74 int ScilabView::getValidDefaultFigureId()
76 if (m_figureList.empty())
83 for (__figureList_iterator it = m_figureList.begin(); it != m_figureList.end(); ++it)
95 bool ScilabView::isEmptyFigureList()
97 return m_figureList.empty();
100 char const* ScilabView::getFigureFromIndex(int figNum)
102 __figureList_iterator it;
104 for (it = m_figureList.begin(); it != m_figureList.end(); ++it)
106 if (it->second == figNum)
108 return it->first.c_str();
114 bool ScilabView::existsFigureId(int id)
116 __figureList_iterator it;
118 for (it = m_figureList.begin(); it != m_figureList.end(); ++it)
120 if (it->second == id)
128 void ScilabView::getFiguresId(int ids[])
130 __figureList_iterator it;
131 int i = (int)(m_figureList.size() - 1);
133 for (it = m_figureList.begin(); it != m_figureList.end(); ++it, --i)
135 //std::cerr << "[ScilabView] DEBUG " << it->first << " <-> " << it->second << std::endl;
140 int ScilabView::getNbFigure(void)
142 return (int)m_figureList.size();
145 void ScilabView::createObject(char const* pstId)
147 //std::cerr << "[ScilabView] ++ createObject UID=" << pstId << std::endl;
149 int *piType = &iType;
151 getGraphicObjectProperty(pstId, __GO_TYPE__, jni_int, (void **)&piType);
152 if (iType != -1 && iType == __GO_FIGURE__)
154 m_figureList[pstId] = -1;
155 setCurrentFigure(pstId);
158 // Register object handle.
159 getObjectHandle(pstId);
162 void ScilabView::deleteObject(char const* pstId)
164 //std::cerr << "[ScilabView] -- deleteObject UID=" << pstId << std::endl;
166 int *piType = &iType;
167 char *pstParentUID = NULL;
170 ** If deleting a figure, remove from figure list.
172 m_figureList.erase(pstId);
175 ** If deleting current figure find another current one,
176 ** if there is no more figure : NULL
178 if (m_currentFigure == pstId) // Deleting current figure
180 char* pstrAxesUID = NULL;
182 if (getNbFigure() != 0)
184 m_currentFigure = m_figureList.rbegin()->first;
185 getGraphicObjectProperty(m_currentFigure.c_str(), __GO_SELECTED_CHILD__, jni_string, (void**)&pstrAxesUID);
186 setCurrentSubWin(pstrAxesUID);
190 setCurrentFigure(NULL);
191 setCurrentSubWin(NULL);
196 ** If deleting current entity, set parent as new current.
198 if (m_currentObject == pstId) // Deleting current object
200 getGraphicObjectProperty(pstId, __GO_PARENT__, jni_string, (void **)&pstParentUID);
201 setCurrentObject(pstParentUID);
204 // Remove the corresponding handle.
205 __handleList_iterator it = m_handleList.find(pstId);
206 m_uidList.erase(it->second);
207 m_handleList.erase(it);
209 deleteDataObject(pstId);
212 void ScilabView::updateObject(char const* pstId, int iProperty)
214 //std::cerr << "[ScilabView] == updateObject UID=" << pstId << " PROPERTY=" << pstProperty << std::endl;
217 ** Take care of update if the value update is ID and object type is a Figure I manage.
219 if (iProperty == __GO_ID__ && m_figureList.find(pstId) != m_figureList.end())
222 int *piNewId = &iNewId;
224 getGraphicObjectProperty(pstId, __GO_ID__, jni_int, (void **)&piNewId);
226 m_figureList[pstId] = iNewId;
227 //std::cerr << "### [ScilabView] updateMap UID=" << pstId << " id=" << iNewId << std::endl;
232 ** Register ScilabView to Controller.
233 ** Must be done after Graphics models are created.
235 void ScilabView::registerToController(void)
237 org_scilab_modules_graphic_objects::CallGraphicController::registerScilabView(getScilabJavaVM());
238 m_figureList.get_allocator().allocate(4096);
239 m_handleList.get_allocator().allocate(4096);
240 m_uidList.get_allocator().allocate(4096);
244 ** Reove ScilabView from Controller.
246 void ScilabView::unregisterToController(void)
248 org_scilab_modules_graphic_objects::CallGraphicController::unregisterScilabView(getScilabJavaVM());
252 ** Set Current Figure UID
254 void ScilabView::setCurrentFigure(char const* UID)
258 m_currentFigure = std::string();
262 m_currentFigure = UID;
267 ** Get Current Figure UID
269 char const* ScilabView::getCurrentFigure()
271 //std::cerr << "[ScilaView] currentFigure = " << (m_currentFigure == NULL ? "NULL !!" : m_currentFigure) << std::endl;
272 if (m_currentFigure.length() == 0)
276 return m_currentFigure.c_str();
280 ** Set Current Object UID
282 void ScilabView::setCurrentObject(char const* UID)
286 m_currentObject = std::string();
290 m_currentObject = UID;
295 ** Get Current Figure UID
297 char const* ScilabView::getCurrentObject()
299 //std::cerr << "[ScilaView] currentObject = " << m_currentObject << std::endl;
300 if (m_currentFigure.length() == 0)
304 return m_currentObject.c_str();
308 ** Set Current SubWin UID
310 void ScilabView::setCurrentSubWin(char const* UID)
314 m_currentSubWin = std::string();
318 m_currentSubWin = UID;
323 ** Get Current Figure UID
325 char const* ScilabView::getCurrentSubWin()
327 //std::cerr << "[ScilaView] currentSubWin = " << m_currentSubWin << std::endl;
328 if (m_currentSubWin.length() == 0)
332 return m_currentSubWin.c_str();
336 ** Scilab only can store long as handle
338 long ScilabView::getObjectHandle(char const* UID)
343 * std::cerr << "UID = " << UID << std::endl;
347 * std::cerr << "UID is null :-S" << std::endl;
349 * __handleList_iterator it2;
350 * std::cerr << "[DEBUG] +++ handleMap +++" << std::endl;
351 * for (it2 = m_handleList.begin() ; it2 != m_handleList.end() ; ++it2)
353 * std::cerr << "UID " << it2->first << " <-> handle " << it2->second << std::endl;
355 * std::cerr << "[DEBUG] +++ handleMap +++" << std::endl;
357 __handleList_iterator it = m_handleList.find(UID);
359 if (it != m_handleList.end())
364 // increase maximum value
365 // register new handle and return it.
367 m_handleList[UID] = m_topHandleValue;
368 m_uidList[m_topHandleValue] = UID;
370 return m_topHandleValue;
373 char const* ScilabView::getObjectFromHandle(long handle)
375 __uidList_iterator it = m_uidList.find(handle);
376 if (it == m_uidList.end())
381 return it->second.c_str();
384 char const* ScilabView::getFigureModel(void)
386 //std::cerr << "[ScilabView] getFigureModel = " << (m_figureModel == NULL ? "!! NULL !!" : m_figureModel) << std::endl;
387 if (m_figureModel.length() == 0)
391 return m_figureModel.c_str();
394 void ScilabView::setFigureModel(char const* UID)
399 char const* ScilabView::getAxesModel(void)
401 //std::cerr << "[ScilabView] getAxesModel = " << (m_axesModel == NULL ? "!! NULL !!" : m_axesModel) << std::endl;
402 if (m_axesModel.length() == 0)
406 return m_axesModel.c_str();
409 void ScilabView::setAxesModel(char const* UID)
415 ** Allocate static class variable.
417 ScilabView::__figureList ScilabView::m_figureList = *new __figureList();
418 ScilabView::__handleList ScilabView::m_handleList = *new __handleList();
419 ScilabView::__uidList ScilabView::m_uidList = *new __uidList();
420 long ScilabView::m_topHandleValue = 0;
421 std::string ScilabView::m_currentFigure;
422 std::string ScilabView::m_currentObject;
423 std::string ScilabView::m_currentSubWin;
424 std::string ScilabView::m_figureModel;
425 std::string ScilabView::m_axesModel;