diff --git a/jni/Main.cpp b/jni/Main.cpp
index 74afc3d..fb0387e 100644
--- a/jni/Main.cpp
+++ b/jni/Main.cpp
@@ -216,7 +216,8 @@ class MainWindows :public ewol::Windows
m_drawer->SetFillY(true);
mySizer->SubWidgetAdd(m_drawer);
-
+ RegisterMultiCast(drawMsgGuiOpen);
+ RegisterMultiCast(drawMsgGuiSave);
};
~MainWindows(void)
@@ -237,11 +238,10 @@ class MainWindows :public ewol::Windows
ewol::Windows::OnReceiveMessage(CallerObject, eventId, data);
DRAW_INFO("Receive Event from the main windows ... : widgetid=" << CallerObject << " ==> " << eventId << " ==> data=\"" << data << "\"" );
- if (eventId == drawerEventRequestOpenFile) {
+ if (eventId == drawMsgGuiOpen) {
ewol::FileChooser* tmpWidget = new ewol::FileChooser();
tmpWidget->SetTitle("Open Files ...");
tmpWidget->SetValidateLabel("Open");
- tmpWidget->SetFolder("/");
PopUpWidgetPush(tmpWidget);
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, drawerEventRequestOpenFileSelected);
} else if (eventId == drawerEventRequestOpenFileSelected) {
@@ -254,6 +254,17 @@ class MainWindows :public ewol::Windows
// get the filename :
etk::UString tmpData = tmpWidget->GetCompleateFileName();
DRAW_DEBUG("Request opening the file : " << tmpData);
+ if (NULL != m_drawer) {
+ m_drawer->Load(tmpData);
+ }
+ } else if (eventId == drawMsgGuiSave) {
+ if (NULL != m_drawer) {
+ if (m_drawer->HasName()) {
+ m_drawer->Save();
+ } else {
+ DRAW_TODO("Later ...");
+ }
+ }
} else if (eventId == drawerEventColorHasChange) {
// the button color has change ==> we really change the current color ...
if (NULL != CallerObject) {
diff --git a/jni/widgetDrawer.cpp b/jni/widgetDrawer.cpp
index 884e3a0..a87b336 100644
--- a/jni/widgetDrawer.cpp
+++ b/jni/widgetDrawer.cpp
@@ -402,9 +402,145 @@ void widgetDrawer::SetColorOnSelected(color_ts newColor)
}
-void widgetDrawer::Load(etk::UString fileName)
+/*
+
+
+
+
+
+
+
+
+
+*/
+void widgetDrawer::Load(etk::UString newFileName)
{
- DRAW_TODO("LATER ... ");
+
+ // Remove all local elements :
+ m_dotList.Clear();
+ m_linkList.Clear();
+ m_selectedList.Clear();
+ m_nearestDot = -1;
+ m_movingPoint = false;
+ m_fileName = newFileName;
+
+ DRAW_DEBUG("open file (DRAWER) \"" << m_fileName << "\"");
+
+ // allocate the document in the stack
+ TiXmlDocument XmlDocument;
+ // open the curent File
+ etk::File fileName(m_fileName, etk::FILE_TYPE_DIRECT);
+ if (false == fileName.Exist()) {
+ DRAW_ERROR("File Does not exist : " << fileName);
+ return;
+ }
+ int32_t fileSize = fileName.Size();
+ if (0==fileSize) {
+ DRAW_ERROR("This file is empty : " << fileName);
+ return;
+ }
+ if (false == fileName.fOpenRead()) {
+ DRAW_ERROR("Can not open the file : " << fileName);
+ return;
+ }
+ // allocate data
+ char * fileBuffer = new char[fileSize+5];
+ if (NULL == fileBuffer) {
+ DRAW_ERROR("Error Memory allocation size=" << fileSize);
+ return;
+ }
+ memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
+ // load data from the file :
+ fileName.fRead(fileBuffer, 1, fileSize);
+ // close the file:
+ fileName.fClose();
+ // load the XML from the memory
+ XmlDocument.Parse((const char*)fileBuffer, 0, TIXML_ENCODING_UTF8);
+
+ TiXmlElement* root = XmlDocument.FirstChildElement( "e2d" );
+ if (NULL == root ) {
+ DRAW_ERROR("(l ?) main node not find: \"e2d\" in \"" << fileName << "\"");
+ return;
+ } else {
+
+ for(TiXmlNode * pNode = root->FirstChild();
+ NULL != pNode;
+ pNode = pNode->NextSibling() ) {
+ if (pNode->Type()==TiXmlNode::TINYXML_COMMENT) {
+ // nothing to do, just proceed to next step
+ } else if (!strcmp(pNode->Value(), "element")) {
+ for(TiXmlNode * pGuiNode = pNode->FirstChild();
+ NULL != pGuiNode;
+ pGuiNode = pGuiNode->NextSibling()) {
+ if (pGuiNode->Type()==TiXmlNode::TINYXML_COMMENT) {
+ // nothing to do, just proceed to next step
+ } else if (!strcmp(pGuiNode->Value(), "dot")) {
+ const char *xxx = pGuiNode->ToElement()->Attribute("x");
+ const char *yyy = pGuiNode->ToElement()->Attribute("y");
+
+ if( NULL != xxx
+ && NULL != yyy) {
+ coord2D_ts pos;
+ double posX, posY;
+ sscanf(xxx, "%lf", &posX);
+ sscanf(yyy, "%lf", &posY);
+ pos.x = posX;
+ pos.y = posY;
+ DRAW_DEBUG("load dot : " << xxx << "," << yyy << " ==>" << pos);
+ m_dotList.PushBack(pos);
+ }
+ } else if (!strcmp(pGuiNode->Value(), "link")) {
+ const char *id[3];
+ const char *color[3];
+ id[0] = pGuiNode->ToElement()->Attribute("id1");
+ id[1] = pGuiNode->ToElement()->Attribute("id2");
+ id[2] = pGuiNode->ToElement()->Attribute("id3");
+ color[0] = pGuiNode->ToElement()->Attribute("color1");
+ color[1] = pGuiNode->ToElement()->Attribute("color2");
+ color[2] = pGuiNode->ToElement()->Attribute("color3");
+
+ if( NULL != id[0]
+ && NULL != id[1]
+ && NULL != id[2]
+ && NULL != color[0]
+ && NULL != color[1]
+ && NULL != color[2]) {
+ link_ts localLink;
+ int r=0;
+ int v=0;
+ int b=0;
+ int a=-1;
+ for(int32_t kkk=0; kkk<3; kkk++) {
+ sscanf(id[kkk], "%d", &localLink.dot[kkk]);
+ sscanf(color[kkk], "#%02x%02x%02x%02x", &r, &v, &b, &a);
+ localLink.color[kkk].red = (float)r/255.0;
+ localLink.color[kkk].green = (float)v/255.0;
+ localLink.color[kkk].blue = (float)b/255.0;
+ if (-1 == a) {
+ localLink.color[kkk].alpha = 1;
+ } else {
+ localLink.color[kkk].alpha = (float)a/255.0;
+ }
+ }
+ DRAW_DEBUG("load link : [" << localLink.dot[0] << "," << localLink.dot[1] << "," << localLink.dot[2] << "] ");
+ DRAW_DEBUG(" col: [" << localLink.color[0] << "," << localLink.color[1] << "," << localLink.color[2] << "] ");
+ m_linkList.PushBack(localLink);
+ }
+ } else {
+ DRAW_ERROR("(l "<Row()<<") node not suported : \""<Value()<<"\" must be [dot,link]");
+ }
+ }
+ } else {
+ DRAW_ERROR("(l "<Row()<<") node not suported : \""<Value()<<"\" must be [element]");
+ }
+ }
+ }
+ if (NULL != fileBuffer) {
+ delete[] fileBuffer;
+ }
+ MarkToReedraw();
}
/*
@@ -419,8 +555,12 @@ void widgetDrawer::Load(etk::UString fileName)
*/
-void widgetDrawer::Save(etk::UString fileName)
+void widgetDrawer::Save(void)
{
+ if (m_fileName == "") {
+ DRAW_ERROR("No filename set ...");
+ return;
+ }
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" );
doc.LinkEndChild( decl );
@@ -433,10 +573,13 @@ void widgetDrawer::Save(etk::UString fileName)
mastertElement->LinkEndChild( element );
for(int32_t iii=0; iiiSetAttribute( "id", iii );
- elementDot->SetAttribute( "x", m_dotList[iii].x );
- elementDot->SetAttribute( "y", m_dotList[iii].y );
+ sprintf(tmpChar, "%f", m_dotList[iii].x);
+ elementDot->SetAttribute( "x", tmpChar );
+ sprintf(tmpChar, "%f", m_dotList[iii].y);
+ elementDot->SetAttribute( "y", tmpChar );
element->LinkEndChild( elementDot );
}
for(int32_t iii=0; iiiSetAttribute( "color3", colorText );
element->LinkEndChild( elementDot );
}
+ //Save Document
+ doc.SaveFile( m_fileName.Utf8Data() );
}
diff --git a/jni/widgetDrawer.h b/jni/widgetDrawer.h
index 2859af9..220166d 100644
--- a/jni/widgetDrawer.h
+++ b/jni/widgetDrawer.h
@@ -94,12 +94,16 @@ class widgetDrawer :public ewol::Widget
etk::VectorType m_selectedList; //!< current selected points
int32_t m_nearestDot; //!< nearest dot from the current cursor
bool m_movingPoint;
+ etk::UString m_fileName;
void removeDotId(int32_t id);
int32_t GetNearestPoint(coord2D_ts pos);
etkFloat_t QuadDistance(coord2D_ts aaa, coord2D_ts bbb);
bool DotIsSelected(int32_t dotId);
+ public:
void Load(etk::UString fileName);
- void Save(etk::UString fileName);
+ void Save(void);
+ void SetFilename(etk::UString fileName) {m_fileName = fileName; };
+ bool HasName(void) { if(m_fileName=="") { return false;} return true; };
};
#endif