diff --git a/ihm/app/controller/Bodies/BodiesManager.js b/ihm/app/controller/Bodies/BodiesManager.js new file mode 100644 index 0000000..48ae810 --- /dev/null +++ b/ihm/app/controller/Bodies/BodiesManager.js @@ -0,0 +1,39 @@ +Ext.define('treps.controller.Bodies.BodiesManager', { + singleton : true, + + constructor: function() { + }, + + loadBodiesStore: function(id, isSc, start, stop, onAfterLoad) { + var me = this; + + //var store = Ext.getStore('Bodies'); + //if (store == null) + + var store = Ext.create('treps.store.Bodies'); + //else store.removeAll(); + + var args = { + 'id' : id, + 'issc' : isSc, + 'starttime' : start, + 'stoptime' : stop + }; + store.getProxy().extraParams = args; + store.load( + { + scope: me, + callback: function(records, operation, success) + { + if (!success) + { + treps.Messages.showError("Cannot get bodies list"); + return; + } + console.log("BodiesManager: store loaded! "+store.count(false)); + if (onAfterLoad != null) + onAfterLoad.call(me,store); + } + }); + } +}); diff --git a/ihm/app/controller/Bodies/BodySelection.js b/ihm/app/controller/Bodies/BodySelection.js new file mode 100644 index 0000000..2c2abef --- /dev/null +++ b/ihm/app/controller/Bodies/BodySelection.js @@ -0,0 +1,93 @@ +Ext.define('treps.controller.Bodies.BodySelection', { + extend: 'Ext.app.Controller', + + requires: [ + 'treps.controller.Bodies.BodiesManager' + ], + + views: [ + 'Steps.TransformationDefinition.BodySelectionPanel', + 'treps.view.Bodies.BodiesCombo' + ], + + refs: [ + { + ref: 'bodiesCenterCombo', + selector: '#centercombo' + }, + { + ref: 'bodiesScCombo', + selector: '#sccombo' + } + ], + + init: function() { + var me = this; + + //console.log('BodySelection init '+this.getView('Steps.TransformationDefinition.BodySelectionPanel')); + + }, + + initStore: function(start,stop,onReady) + { + var me = this; + this.getView('Steps.TransformationDefinition.BodySelectionPanel').create(); + console.log("bodies centr combo: "+me.getBodiesCenterCombo()); + console.log("bodies sc combo: "+me.getBodiesScCombo()); + //if(isSc) { + treps.controller.Bodies.BodiesManager.loadBodiesStore(treps.model.Session.get('id'),'true',start, stop, + function(store) { + //console.log(me); + me.getBodiesScCombo().store = store; + if (onReady != null) { + treps.controller.Bodies.BodiesManager.loadBodiesStore(treps.model.Session.get('id'),'false',start, stop, + function(store) { + //console.log(me); + me.getBodiesCenterCombo().store = store; + if (onReady != null) { + onReady.call(me, store); + } + } + ); + } + } + ); + //} else { +//} + }, + + getBodySelWin: function(pTitle) { + var me = this; + console.log(this.getView('Steps.TransformationDefinition.BodySelectionPanel')); + return Ext.create('Ext.window.Window', { + title: pTitle, + layout: 'fit', + modal: true, + maximizable: false, + collapsible:false, + floating:true, + closable:false, + centered:true, + //items:[{xtype:'bodies_panel'}] + }); + }, + + //get 'id name' string of selected sc + getScBody: function() { + return this.getBodiesScCombo().getValue()+' '+this.getBodiesScCombo().getRawValue(); + }, + + setScBody: function(body) { + this.getBodiesScCombo().setValue(body); + }, + + //get 'id name' string of selected natural body + getCenterBody: function() { + return this.getBodiesCenterCombo().getValue()+' '+this.getBodiesCenterCombo().getRawValue(); + }, + + setCenterBody: function(body) { + this.getBodiesCenterCombo().setValue(body); + } + +}); diff --git a/ihm/app/controller/Frames/FramesSelection.js b/ihm/app/controller/Frames/FramesSelection.js index b2bf2c7..be86981 100644 --- a/ihm/app/controller/Frames/FramesSelection.js +++ b/ihm/app/controller/Frames/FramesSelection.js @@ -2,7 +2,9 @@ Ext.define('treps.controller.Frames.FramesSelection', { extend: 'Ext.app.Controller', requires: [ - 'treps.controller.Frames.FramesManager' + 'treps.controller.Frames.FramesManager', + 'treps.controller.Bodies.BodySelection', + 'treps.controller.Data.Store.DataStoreManager' ], views: [ @@ -10,19 +12,62 @@ Ext.define('treps.controller.Frames.FramesSelection', { ], refs: [ - { - ref: 'sourceCombo', - selector: '#srcSysFrame' - }, + { + ref: 'sourceCombo', + selector: '#srcSysFrame' + }, { ref: 'destCombo', selector: '#destSysFrame' } ], + + srcCenter : '', + dstCenter : '', - init: function() { - var me = this; - }, + init: function() { + var me = this; + //timeDefController.init(); + + this.control({ + '#srcSysFrame': { + select: me.onSrcFrameSelect, + scope: me + } + }); + this.control({ + '#destSysFrame': { + select: me.onDstFrameSelect, + scope: me + } + }); + + }, + + onSrcFrameSelect: function() { + var me = this; + var timeDefController = treps.app.getController('Times.SourceTimeSelection'); + if((me.getSrcFrame()=='RTN') || (me.getSrcFrame()=='RTP')) { + if(timeDefController.getTimeFormat() == "") {//check time is defined + treps.Messages.showWarning("You must select a time field to use RTN/RTP coordinate system."); + me.getSourceCombo().setValue(null); + } else { + me.selectRTBodies('Select bodies for '+me.getSrcFrame(),me.getSourceCombo()); + } + } + }, + onDstFrameSelect: function() { + var me = this; + var timeDefController = treps.app.getController('Times.SourceTimeSelection'); + if((me.getDstFrame()=='RTN') || (me.getDstFrame()=='RTP')) { + if(timeDefController.getTimeFormat() == "") {//check time is defined + treps.Messages.showWarning("You must select a time field to use RTN/RTP coordinate system."); + me.getDestCombo().setValue(null); + } else { + me.selectRTBodies('Select bodies for '+me.getDstFrame(),me.getDestCombo()); + } + } + }, initStore: function(onReady) { @@ -37,6 +82,66 @@ Ext.define('treps.controller.Frames.FramesSelection', { onReady.call(me, store); }); }, + + + //show RTN/RTP bodies selection and returns center formated string as follow: + // centerid centername scid scname + + ctrlAdded: false, + currentCombo: undefined, + currentBodyWin: undefined, + + selectRTBodies: function(pTitle,frameCombo) { + var me = this; + //var bodySelCtrl = treps.app.getController('treps.controller.Bodies.BodySelection'); + var bodySelCtrl = Ext.create('treps.controller.Bodies.BodySelection'); + treps.controller.Data.Store.DataStoreManager.getStore('SourceDataStore'); + var bodySelWin = bodySelCtrl.getBodySelWin(pTitle); + this.currentCombo=frameCombo; + this.currentBodyWin = bodySelWin; + if(!this.ctrlAdded) { + this.control({ + 'bodies_panel > #okbtn': { + click: function() { + var center = bodySelCtrl.getCenterBody()+' '+bodySelCtrl.getScBody(); + if(this.currentCombo==me.getSourceCombo()) { + me.srcCenter = center; + console.log("set src center "+me.srcCenter+" dst="+me.dstCenter); + } + if(this.currentCombo==me.getDestCombo()) { + me.dstCenter = center; + console.log("set dst center "+me.dstCenter+" src="+me.srcCenter); + } + me.currentBodyWin.close(); + }, + scope: me + } + }); + this.ctrlAdded = true; + } + var srcStore = treps.controller.Data.Store.DataStoreManager.getStore('SourceDataStore'); + var gridController = treps.app.getController('Data.Grid.SourceDataGrid'); + var timeCol = gridController.getFirstColumnDataIndex(gridController.getSourceGrid()); + bodySelCtrl.initStore(srcStore.getAt(0).get(timeCol), srcStore.getAt(srcStore.totalCount-1).get(timeCol), + function(lBodies){ + console.log("combo Sc found? "+bodySelCtrl.getBodiesScCombo().store.count(false)); + console.log("combo Center found? "+bodySelCtrl.getBodiesCenterCombo().store.count(false)); + //for RTN, select default sun value + if(frameCombo.getValue()=='RTN') bodySelCtrl.getBodiesCenterCombo().setValue('10'); + bodySelWin.add(bodySelCtrl.getBodiesScCombo().ownerCt); + bodySelWin.doLayout(); + bodySelWin.show(); + } + ); + + }, + + getSrcCenter: function() { + return this.srcCenter; + }, + getDstCenter: function() { + return this.dstCenter; + }, getSrcFrame: function() { return this.getSourceCombo().getValue(); @@ -69,6 +174,7 @@ Ext.define('treps.controller.Frames.FramesSelection', { treps.Messages.showError('Please select a destination frame'); return false; } + return true; } diff --git a/ihm/app/controller/Steps/TransformationDefinitionStep.js b/ihm/app/controller/Steps/TransformationDefinitionStep.js index f15810f..4641f06 100644 --- a/ihm/app/controller/Steps/TransformationDefinitionStep.js +++ b/ihm/app/controller/Steps/TransformationDefinitionStep.js @@ -51,6 +51,10 @@ Ext.define('treps.controller.Steps.TransformationDefinitionStep', { scope: me } ); + + + + }, @@ -95,8 +99,8 @@ Ext.define('treps.controller.Steps.TransformationDefinitionStep', { onAfterLoad: function(store, records, successful, eOpts) { + var me = this; var gridController = treps.app.getController('Data.Grid.SourceDataGrid'); - gridController.setTotalInHeader(store.totalCount); }, @@ -197,35 +201,55 @@ Ext.define('treps.controller.Steps.TransformationDefinitionStep', { var vecDefController = treps.app.getController('Vectors.VecDefGrid'); var timeDefController = treps.app.getController('Times.SourceTimeSelection'); timeDefController.init(); + + var srcStore = treps.controller.Data.Store.DataStoreManager.getStore('SourceDataStore'); + var timeCol = gridController.getFirstColumnDataIndex(gridController.getSourceGrid()); var dataGrid = gridController.getSourceGrid(); - var args = { - 'id' : treps.model.Session.get('id'), - 'srcframe' : framesDefController.getSrcFrame(), - 'dstframe' : framesDefController.getDstFrame(), - 'vectors' : vecDefController.getVectorsStr(), - 'timeformatid' : timeDefController.getTimeFormat(), - 'timepattern' : timeDefController.getTimePattern(), - 'timefieldid' : gridController.getFirstColumnDataIndex(dataGrid) - }; + + + + var srcFrame = framesDefController.getSrcFrame(); + var dstFrame = framesDefController.getDstFrame() + var srcCenter = framesDefController.getSrcCenter(); + var dstCenter = framesDefController.getDstCenter(); + + console.log('found srccenter: '+srcCenter+' / '+dstCenter); var infoMsg = []; - if ((args.srcframe == null) && (args.dstframe == null)) + if ((srcFrame == null) && (dstFrame == null)) infoMsg.push("No frames selected."); else { - if (args.srcframe == args.dstframe) + if (srcFrame == dstFrame) infoMsg.push("Source and destination frames are identical."); - if ((args.srcframe != args.dstframe) && (args.timeformatid == "")) + if ((srcFrame != dstFrame) && (timeDefController.getTimeFormat() == "")) infoMsg.push("No time field selected. You must be sure that selected transformation don't need to use the time. If time needed, it will be set to 01/01/1970."); - if (args.vectors == "") + if (vecDefController.getVectorsStr() == "") infoMsg.push("No vector defined. The full source data will be used during the next step."); } + + var args = { + 'id' : treps.model.Session.get('id'), + 'srcframe' : srcFrame, + 'srccenter' : srcCenter, + 'dstframe' : dstFrame, + 'dstcenter' : dstCenter, + 'starttime' : srcStore.getAt(0).get(timeCol), + 'stoptime' : srcStore.getAt(srcStore.totalCount-1).get(timeCol), + 'vectors' : vecDefController.getVectorsStr(), + 'timeformatid' : timeDefController.getTimeFormat(), + 'timepattern' : timeDefController.getTimePattern(), + 'timefieldid' : gridController.getFirstColumnDataIndex(dataGrid) + }; + + + if (infoMsg.length == 0) this.callRequest(args,afterrequest); else @@ -243,10 +267,12 @@ Ext.define('treps.controller.Steps.TransformationDefinitionStep', { me.callRequest(args,afterrequest); } ); - }var session = treps.model.Session; + } + var session = treps.model.Session; }, + doInitStep: function() { var me = this; var session = treps.model.Session; diff --git a/ihm/app/model/Body.js b/ihm/app/model/Body.js new file mode 100644 index 0000000..758a106 --- /dev/null +++ b/ihm/app/model/Body.js @@ -0,0 +1,18 @@ +Ext.define('treps.model.Body', { + extend: 'Ext.data.Model', + + fields: [ + { + name: 'id', type: 'string' + }, + { + name: 'fullname', type: 'string' + }, + { + name: 'startTime', type: 'date', dateFormat: 'c' + }, + { + name: 'endTime', type: 'date', dateFormat: 'c' + } + ] +}); diff --git a/ihm/app/store/Bodies.js b/ihm/app/store/Bodies.js new file mode 100644 index 0000000..08891d9 --- /dev/null +++ b/ihm/app/store/Bodies.js @@ -0,0 +1,25 @@ +Ext.define('treps.store.Bodies', { + extend: 'Ext.data.Store', + + model: 'treps.model.Body', + + sorters: [{ + property: 'fullname', + direction: 'ASC' + }], + + sortOnLoad: true, + remoteSort: false, + + proxy: { + type: 'direct', + reader : { + type : 'json', + root : 'bodies' + }, + api: { + read : "TREPSAction.getBodiesList" + } + } + +}); diff --git a/ihm/app/view/Bodies/BodiesCombo.js b/ihm/app/view/Bodies/BodiesCombo.js new file mode 100644 index 0000000..b298165 --- /dev/null +++ b/ihm/app/view/Bodies/BodiesCombo.js @@ -0,0 +1,28 @@ +Ext.define('treps.view.Bodies.BodiesCombo', { + extend: 'Ext.form.field.ComboBox', + alias: 'widget.bodies_combo', + + editable:false, + + valueField: 'id', + + queryMode: 'local', + + emptyText: 'Choose a body', + + tpl: Ext.create('Ext.XTemplate', + '', + '
{fullname}
', + '
' + ), + + displayTpl: Ext.create('Ext.XTemplate', + '', + '', + '{fullname}', + '', + '', + '', + '' + ) +}); diff --git a/ihm/app/view/Steps/TransformationDefinition/BodySelectionPanel.js b/ihm/app/view/Steps/TransformationDefinition/BodySelectionPanel.js new file mode 100644 index 0000000..82f3ab5 --- /dev/null +++ b/ihm/app/view/Steps/TransformationDefinition/BodySelectionPanel.js @@ -0,0 +1,53 @@ +Ext.define('treps.view.Steps.TransformationDefinition.BodySelectionPanel' ,{ + extend: 'Ext.form.Panel', + + alias: 'widget.bodies_panel', + + requires: [ + 'treps.view.Bodies.BodiesCombo' + ], + + initComponent: function() { + this.callParent(arguments); + }, + + /*tools: [ + { + type: 'help', + pageId: 'bodies' + } + ], + */ + //title: 'Body selection', + + layout: { + type: 'vbox', + align: 'center', + padding: 5, + margin: 5 + }, + + items: [ + { + xtype: 'bodies_combo', + id: 'centercombo', + fieldLabel: 'Center', + labelWidth: 150, + padding: 5, + flex: 1 + }, + { + xtype: 'bodies_combo', + id: 'sccombo', + fieldLabel: 'Spacecraft', + labelWidth: 150, + padding: 5, + flex: 1 + }, + { + xtype: 'button', + text: 'OK', + id: 'okbtn' + } + ] +}); diff --git a/server/kernel/data/frames.xml b/server/kernel/data/frames.xml index d4bcec4..48881fd 100644 --- a/server/kernel/data/frames.xml +++ b/server/kernel/data/frames.xml @@ -119,7 +119,7 @@ Heliocentric Earth Ecliptic - The Heliocentric Earth Ecliptic frame is defined as follows ): + The Heliocentric Earth Ecliptic frame is defined as follows : - X-Y plane is defined by the Earth Mean Ecliptic plane of date, therefore, the +Z axis is the primary vector,and it defined as @@ -141,14 +141,24 @@ ECLIPJ2000 centered on Jupiter - + The value for the obliquity of the + ecliptic at J2000 is taken from + of 'Explanatory Supplement to the Astronomical Almanac' + edited by P. Kenneth Seidelmann. University Science + Books, 20 Edgehill Road, Mill Valley, CA 94941 (1992) + page 114 equation 3.222-1 ECLIPJ2000 centered on Saturn - + The value for the obliquity of the + ecliptic at J2000 is taken from + of 'Explanatory Supplement to the Astronomical Almanac' + edited by P. Kenneth Seidelmann. University Science + Books, 20 Edgehill Road, Mill Valley, CA 94941 (1992) + page 114 equation 3.222-1 @@ -533,7 +543,12 @@ ECLIPJ2000 centered on Mercury - + The value for the obliquity of the + ecliptic at J2000 is taken from + of 'Explanatory Supplement to the Astronomical Almanac' + edited by P. Kenneth Seidelmann. University Science + Books, 20 Edgehill Road, Mill Valley, CA 94941 (1992) + page 114 equation 3.222-1 @@ -581,11 +596,18 @@ Ganymede Phi-Omega +In those Cartesian coordinate system (referred to as MphiO, M=Ganymede, Europa, Io, Callisto), +X is along the flow direction, Y is along the Moon-Jupiter vector, and Z is along the spin axis. +These coordinates are analogous to the earth-centered GSE coordinates that relate to the direction of +flow of the solar wind onto Earth's environment +All the vectors are geometric: no aberration corrections are used. Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -628,26 +650,36 @@ Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -739,7 +771,8 @@ Body-Fixed Frame - Same as SYSTEM_3 + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -770,6 +803,8 @@ flow of the solar wind onto Earth's environment Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -888,7 +923,12 @@ flow of the solar wind onto Earth's environment ECLIPJ2000 centered on Uranus - + The value for the obliquity of the + ecliptic at J2000 is taken from + of 'Explanatory Supplement to the Astronomical Almanac' + edited by P. Kenneth Seidelmann. University Science + Books, 20 Edgehill Road, Mill Valley, CA 94941 (1992) + page 114 equation 3.222-1 @@ -913,6 +953,8 @@ flow of the solar wind onto Earth's environment Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -923,7 +965,12 @@ flow of the solar wind onto Earth's environment ECLIPJ2000 centered on Neptune - + The value for the obliquity of the + ecliptic at J2000 is taken from + of 'Explanatory Supplement to the Astronomical Almanac' + edited by P. Kenneth Seidelmann. University Science + Books, 20 Edgehill Road, Mill Valley, CA 94941 (1992) + page 114 equation 3.222-1 @@ -948,6 +995,8 @@ flow of the solar wind onto Earth's environment Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -957,7 +1006,12 @@ flow of the solar wind onto Earth's environment ECLIPJ2000 centered on Pluto - + The value for the obliquity of the + ecliptic at J2000 is taken from + of 'Explanatory Supplement to the Astronomical Almanac' + edited by P. Kenneth Seidelmann. University Science + Books, 20 Edgehill Road, Mill Valley, CA 94941 (1992) + page 114 equation 3.222-1 @@ -982,6 +1036,8 @@ flow of the solar wind onto Earth's environment Body-Fixed Frame + Archinal, B.A., Acton, C.H., A’Hearn, M.F. et al. Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015. + Celest Mech Dyn Astr 130, 22 (2018). https://doi.org/10.1007/s10569-017-9805-5 @@ -1086,5 +1142,40 @@ flow of the solar wind onto Earth's environment - All vectors are geometric: no aberration corrections are used. + + Sun-Spaceraft coordinate system + + RTN Frame is defined as follows: + - R is positive from the Sun to the spacecraft. + - T is omega cross R, where omega is the sun spin axis. + - N is R cross T, which completes the right-handed system. + + This frame assumes the instantaneous center is located at the Sun, + and not the spacecraft. Further, the axes are associated + with the normal X, Y, and Z in the following manner: + + - R -> X + - T -> Y + - N -> Z + + + + Planet-Spaceraft coordinate system + + The RTP frame is defined as follows: + - R is positive from the Planet to the spacecraft. + - T is omega cross R, where omega is the planet spin axis. + - P is R cross T, which completes the right-handed system. + + + This frame assumes the instantaneous center is located at planet + and not the spacecraft. Further, the axes are associated + with the normal X, Y, and Z in the following manner: + + - R -> X + - Theta -> Y + - Phi -> Z + + diff --git a/server/kernel/src/Bodies/BodiesAbstract.cpp b/server/kernel/src/Bodies/BodiesAbstract.cpp new file mode 100644 index 0000000..776d722 --- /dev/null +++ b/server/kernel/src/Bodies/BodiesAbstract.cpp @@ -0,0 +1,107 @@ +#include "BodiesAbstract.h" + +#include +#include + +#include "../Common/Toolbox.h" +#include "../TimeManager/TimeManager.h" + +using namespace std; +using namespace TREPS::Common; +using namespace TREPS::File; +using namespace TREPS::TimeManager; + +namespace TREPS +{ + namespace Bodies + { + BodiesAbstractClass::BodiesAbstractClass(RequestAbstractClass *trepsRequest) : app(NULL), trepsRequest(trepsRequest), + errorMsg(""), request(NULL), result(NULL) + { + this->app = ApplicationClass::getInstance(); + + this->request = new BodiesRequestClass(); + + this->result = new BodiesResultClass(); + } + + BodiesAbstractClass::~BodiesAbstractClass(void) + { + if (this->request != NULL) + { + delete this->request; + this->request = NULL; + } + + if (this->result != NULL) + { + delete this->result; + this->result = NULL; + } + } + + bool BodiesAbstractClass::init(const bool isSc, const t_Time *startTime, const t_Time *endTime) + { + this->trepsRequest->setStatus("Initialize bodies abstract class"); + + if (this->request == NULL) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot init bodies request"); + return false; + } + + this->request->setIsSc(isSc); + this->request->setTimes(startTime, endTime); + + //save request file +/* if (!this->request->saveToFile(bodiesRequest)) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot save bodies request file"); + return false; + } +*/ + return true; + } + + bool BodiesAbstractClass::writeResult(const char *resultPath) + { + this->trepsRequest->setStatus("Finalize getbodies XML result"); + + FileWriterBodiesClass *fileWriter = new FileWriterBodiesClass(); + map attributes; + attributes.clear(); + + //init the file writer + if (!fileWriter->init(resultPath, &attributes)) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to init the file to write " << resultPath); + delete fileWriter; + return false; + } + + //write file data + if (!fileWriter->writeData(result->getBodies())) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to write data"); + delete fileWriter; + return false; + } + + //save file + bool res = fileWriter->save(); + + if (!res) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to save file"); + } + + delete fileWriter; + return res; + } + + string BodiesAbstractClass::getLastError(void) + { + return this->errorMsg; + } + } +} diff --git a/server/kernel/src/Bodies/BodiesAbstract.h b/server/kernel/src/Bodies/BodiesAbstract.h new file mode 100644 index 0000000..653bb5d --- /dev/null +++ b/server/kernel/src/Bodies/BodiesAbstract.h @@ -0,0 +1,59 @@ +#ifndef BODIESABSTRACT_H +#define BODIESABSTRACT_H + +#include + +#include "BodiesRequest.h" +#include "BodiesResult.h" +#include "../Application/Application.h" +#include "../File/FileWriterBodies.h" +#include "../RequestManager/RequestAbstract.h" + +using namespace std; +using namespace TREPS::Application; +using namespace TREPS::RequestManager; + +namespace TREPS +{ + namespace Bodies + { + class BodiesAbstractClass + { + public : + BodiesAbstractClass(RequestAbstractClass *trepsRequest); + + virtual ~BodiesAbstractClass(void) = 0; + + //init request + bool init(const bool isSc, const t_Time *startTime, const t_Time *endTime); + + //get list of available bodies for this engine + //virtual t_StringList getBodies(const t_Time *startTime, const t_Time *endTime) = 0; + + //run request + virtual bool run() = 0; + + //write request result + bool writeResult(const char *resultPath); + + //get last error message + string getLastError(void); + + protected : + ApplicationClass *app; + + RequestAbstractClass *trepsRequest; + + string errorMsg; + + //get source vector list + //t_VectorList getSrcVectorsList(const char *vectorsDef, const char *srcFrame); + + BodiesRequestClass *request; + + BodiesResultClass *result; + }; + } +} + +#endif diff --git a/server/kernel/src/Bodies/BodiesCDPP3DView.cpp b/server/kernel/src/Bodies/BodiesCDPP3DView.cpp new file mode 100644 index 0000000..6db67b9 --- /dev/null +++ b/server/kernel/src/Bodies/BodiesCDPP3DView.cpp @@ -0,0 +1,168 @@ +#include "BodiesCDPP3DView.h" + +#include + +//#include "../../CDPP3DViewSOAPClient/cdppBinder.nsmap" +#include "../../CDPP3DViewSOAPClient/cdpp3dviewcdppBinderProxy.h" +#include "../Common/Toolbox.h" +//#include "../DataRetriever/DataRetriever.h" +//#include "../File/FileLoaderManager.h" +#include "../TimeManager/TimeManager.h" + +using namespace TREPS::Common; +using namespace TREPS::TimeManager; + +namespace TREPS +{ + namespace Bodies + { + BodiesCDPP3DViewClass::BodiesCDPP3DViewClass(RequestAbstractClass *trepsRequest):BodiesAbstractClass(trepsRequest), + client(NULL) + { + //init SOAP client for 3DView Web Service + this->client = new cdppBinderProxy(SOAP_IO_KEEPALIVE); + } + + BodiesCDPP3DViewClass::~BodiesCDPP3DViewClass(void) + { + if (this->client != NULL) + { + delete this->client; + this->client = NULL; + } + } + + bool BodiesCDPP3DViewClass::run() + { + this->errorMsg = ""; + + + //for each vector + //for (t_VectorList::iterator it=this->request->getSrcVectors()->begin(); it != this->request->getSrcVectors()->end(); ++it) + //{ + + string generalStatus = ""; + generalStatus += " - Running step : list bodies"; + this->trepsRequest->setStatus(generalStatus.c_str()); + t_Bodies bodies = this->callListBodiesRequest(request->getIsSc()); + + generalStatus = "Bodies found: "; + generalStatus += bodies.size(); + generalStatus += " - Running step : filter bodies result"; + //this->trepsRequest->setStatus(generalStatus.c_str()); + + LOG4CXX_INFO(this->app->getLog()->getPtr(),"listBodies result : " << bodies.size() << " bodies found"); + + t_Bodies filteredBodies; + //get time manager instance + TimeManagerClass *timeMgr = TimeManagerClass::getInstance(); + + for (unsigned int i=0;iapp->getLog()->getPtr(),"BodiesCDPP3DView.run(): in for : " << i); + ns4__Body* body = bodies.at(i); + ns4__TimeRange* coverage = body->coverage; + if(coverage==0) continue; + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): body " <name.c_str()<<"/"<app->getLog()->getPtr(),"BodiesCDPP3DView.run(): body " <name.c_str()<<"/"<startTime<<"/"<stopTime); + time_t lBodyStart = coverage->startTime; + time_t lBodyStop = coverage->stopTime; + time_t lFileStart = timeMgr->to_TIMESTAMP(request->getStartTime()); + time_t lFileStop = timeMgr->to_TIMESTAMP(request->getStopTime()); + + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): compare body start: " << ctime(&lBodyStart)); + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): compare body stop: " << ctime(&lBodyStop)); + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): compare filter start: " << ctime(&lFileStart)); + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): compare filter stop: " << ctime(&lFileStop)); + + //check if body timerange covers file timerange + if((lBodyStart-lFileStart)<0 && (lBodyStop-lFileStop)>0) { + /*ns4__Body *lNewBody = soap_new_req_ns4__Body(body->soap, body->naifId, body->modelId, body->name, + soap_new_req_ns4__TimeRange(body->soap, lBodyStart, lBodyStop), + body->type, body->color, body->size, + body->prefFrame, body->prefCenter, body->prefStarSubset); + */ + filteredBodies.push_back(body); + } + + + + + } + LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): filtered bodies result : " << filteredBodies.size() << " bodies found"); + + //copy result xml file in op workspace + generalStatus = "Bodies filtered: "; + generalStatus += filteredBodies.size(); + generalStatus += " - Running step : Save bodies result"; + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): set Status"); + //this->trepsRequest->setStatus(generalStatus.c_str()); + //add result + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.run(): set result"); + this->result->init(filteredBodies); + //} + + return true; + } + + + t_Bodies BodiesCDPP3DViewClass::callListBodiesRequest(bool isSc) + { + bool res = false; + t_Bodies response; + + string method = "listBodies"; + + //Init 3DView listBodies request + _ns3__listBodies listBodiesRequest; + _ns3__listBodiesResponse listBodiesResponse; + if(isSc) { + listBodiesRequest.pType = ns4__BodyType__SPACECRAFT; + LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.callListBodiesRequest(): type : sc"); + res = (this->client->listBodies(&listBodiesRequest,&listBodiesResponse) == SOAP_OK); + } else { + listBodiesRequest.pType = ns4__BodyType__PLANET; + LOG4CXX_INFO(this->app->getLog()->getPtr(),"BodiesCDPP3DView.callListBodiesRequest(): type : planet"); + //ns4__BodyType__PLANET, ///< xs:string value="PLANET" + //ns4__BodyType__SATELLITE, ///< xs:string value="SATELLITE" + //ns4__BodyType__COMET, ///< xs:string value="COMET" + //ns4__BodyType__ASTEROID, ///< xs:string value="ASTEROID" + res = (this->client->listBodies(&listBodiesRequest,&listBodiesResponse) == SOAP_OK); + t_Bodies planets = listBodiesResponse.return_; +/* listBodiesRequest.pType = ns4__BodyType__SATELLITE; + res = (this->client->listBodies(&listBodiesRequest,&listBodiesResponse) == SOAP_OK); + for(unsigned i=0;ideleteTimeList(listNewFrameOrbRequest.pDateTimeInput); + //this->deleteVectorTuple3d(listNewFrameOrbRequest.pDataInput); + //#endif + + if (!res) + { + this->errorMsg = "Error during the call of "; + this->errorMsg += method; + this->errorMsg += " of 3DView Web Service"; + if (this->client->soap_fault_string() != NULL) + { + this->errorMsg += " ("; + this->errorMsg += this->client->soap_fault_string(); + this->errorMsg += ")"; + } + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + + } else { + response = listBodiesResponse.return_; + } + + return response; + } + } +} diff --git a/server/kernel/src/Bodies/BodiesCDPP3DView.h b/server/kernel/src/Bodies/BodiesCDPP3DView.h new file mode 100644 index 0000000..fff67c0 --- /dev/null +++ b/server/kernel/src/Bodies/BodiesCDPP3DView.h @@ -0,0 +1,42 @@ +#ifndef BODIESCDPP3DVIEW_H +#define BODIESCDPP3DVIEW_H + + + +#include "BodiesAbstract.h" + +#define CDPP3DVIEW_TIME_PATTERN "[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss].[mls]" + + +namespace TREPS +{ + namespace Bodies + { + typedef vector t_Bodies; + + class BodiesCDPP3DViewClass : public BodiesAbstractClass + { + public : + BodiesCDPP3DViewClass(RequestAbstractClass *trepsRequest); + + ~BodiesCDPP3DViewClass(void); + + //retreive bodies + bool run(); + + + private : + //pointer to the WS client + cdppBinderProxy *client; + //retreive all bodies + t_Bodies callListBodiesRequest(const bool isSc); + //filter bodies with their coverage + t_Bodies filterBodiesRequest(const t_Time *startDate, const t_Time *endDate); + + + + }; + } +} + +#endif diff --git a/server/kernel/src/Bodies/BodiesRequest.cpp b/server/kernel/src/Bodies/BodiesRequest.cpp new file mode 100644 index 0000000..f5fc326 --- /dev/null +++ b/server/kernel/src/Bodies/BodiesRequest.cpp @@ -0,0 +1,49 @@ +#include "BodiesRequest.h" + +#include "../Common/Toolbox.h" +#include "../XMLManager/XMLManager.h" + +using namespace TREPS::Common; +using namespace TREPS::XMLManager; + +namespace TREPS +{ + namespace Bodies + { + BodiesRequestClass::BodiesRequestClass(void) : startTime(), stopTime() + { + } + + BodiesRequestClass::~BodiesRequestClass(void) + { + } + + + void BodiesRequestClass::setIsSc(bool isSc){ + this->isSc=isSc; + } + + bool BodiesRequestClass::getIsSc(void) { + return this->isSc; + } + + + + void BodiesRequestClass::setTimes(const t_Time *startTime, const t_Time *stopTime) + { + this->startTime = *startTime; + this->stopTime = *stopTime; + } + + t_Time BodiesRequestClass::getStartTime(void) const + { + return this->startTime; + } + + t_Time BodiesRequestClass::getStopTime(void) const + { + return this->stopTime; + } + + } +} diff --git a/server/kernel/src/Bodies/BodiesRequest.h b/server/kernel/src/Bodies/BodiesRequest.h new file mode 100644 index 0000000..69e5ea4 --- /dev/null +++ b/server/kernel/src/Bodies/BodiesRequest.h @@ -0,0 +1,42 @@ +#ifndef BODIESREQUEST_H +#define BODIESREQUEST_H + +#include + +#include "../Common/TREPSTypes.h" + +using namespace std; +using namespace TREPS::Common; + +namespace TREPS +{ + namespace Bodies + { + class BodiesRequestClass + { + public : + BodiesRequestClass(void); + + ~BodiesRequestClass(void); + + //set spacecraft type query boolean + void setIsSc(bool isSc); + //get spacecraft type query boolean + bool getIsSc(void); + + //set times + void setTimes(const t_Time *startTime, const t_Time *stopTime); + //get start time + t_Time getStartTime(void) const; + //get end time + t_Time getStopTime(void) const; + + private : + bool isSc; + t_Time startTime; + t_Time stopTime; + }; + } +} + +#endif diff --git a/server/kernel/src/Bodies/BodiesResult.cpp b/server/kernel/src/Bodies/BodiesResult.cpp new file mode 100644 index 0000000..297dd3e --- /dev/null +++ b/server/kernel/src/Bodies/BodiesResult.cpp @@ -0,0 +1,31 @@ +#include "BodiesResult.h" + +namespace TREPS +{ + namespace Bodies + { + BodiesResultClass::BodiesResultClass(void) : app(NULL) + { + this->app = ApplicationClass::getInstance(); + + } + + BodiesResultClass::~BodiesResultClass(void) + { + } + + t_Bodies *BodiesResultClass::getBodies(void) const + { + return const_cast(&this->bodies); + } + + bool BodiesResultClass::init(t_Bodies bodies) + { + //reset result + this->bodies = bodies; + + return true; + } + + } +} diff --git a/server/kernel/src/Bodies/BodiesResult.h b/server/kernel/src/Bodies/BodiesResult.h new file mode 100644 index 0000000..7488dc7 --- /dev/null +++ b/server/kernel/src/Bodies/BodiesResult.h @@ -0,0 +1,44 @@ +#ifndef BODIESRESULT_H +#define BODIESRESULT_H + +#include "../Common/TREPSTypes.h" +#include "../Application/Application.h" +#include "../../CDPP3DViewSOAPClient/cdpp3dviewcdppBinderProxy.h" +//#include "../DataRecord/DataRecordList.h" +//#include "../Export/ExportManager.h" + + +using namespace TREPS::Common; +using namespace TREPS::Application; + +namespace TREPS +{ + namespace Bodies + { + //declare stype as in Bodies/BodiesCDPP3DView.h + typedef vector t_Bodies; + + class BodiesResultClass + { + public : + BodiesResultClass(void); + + ~BodiesResultClass(void); + + //init listBodies result + bool init(t_Bodies bodies); + + //get result + t_Bodies *getBodies(void) const; + + + private : + ApplicationClass *app; + + t_Bodies bodies; + + }; + } +} + +#endif diff --git a/server/kernel/src/File/FileWriterBodies.cpp b/server/kernel/src/File/FileWriterBodies.cpp new file mode 100644 index 0000000..8e2fad0 --- /dev/null +++ b/server/kernel/src/File/FileWriterBodies.cpp @@ -0,0 +1,196 @@ +#include "FileWriterBodies.h" + +#include + +#include "../TimeManager/TimeManager.h" +#include "../Common/Toolbox.h" + +using namespace TREPS::Common; +using namespace TREPS::TimeManager; + +namespace TREPS +{ + namespace File + { + FileWriterBodiesClass::FileWriterBodiesClass(void): filePath(""), writer(NULL) + { + this->app = ApplicationClass::getInstance(); + this->writer = new XMLManagerClass(); + } + + FileWriterBodiesClass::~FileWriterBodiesClass(void) + { + if (this->writer != NULL) + { + delete this->writer; + this->writer = NULL; + } + } + + bool FileWriterBodiesClass::init(const char *file_path, const map *attributes) + { + if (!this->close()) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot close previous document"); + return false; + } + + if (!this->writer->create("treps")) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot init xml document"); + return false; + } + + Node *rootNode = this->writer->getRootNode(); + + if (rootNode == NULL) + { + this->close(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get root node"); + return false; + } + +/* if (!this->writer->addAttributeToNode("version", "1.2", rootNode)) + { + this->close(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot set VOTable version"); + return false; + } +*/ +/* if (!this->writer->addAttributeToNode("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", rootNode)) + { + this->close(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot set xmlns:xsi"); + return false; + } +*/ +/* + if (!this->writer->addAttributeToNode("xmlns", "http://www.ivoa.net/xml/VOTable/v1.2", rootNode)) + { + this->close(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot set xmlns"); + return false; + } + + if (!this->writer->addAttributeToNode("xmlns:stc", "http://www.ivoa.net/xml/STC/v1.30", rootNode)) + { + this->close(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot set xmlns:stc"); + return false; + } +*/ + Node *bodiesNode = this->writer->addChildToRoot("bodies"); + + if (bodiesNode == NULL) + { + this->close(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot add bodies node"); + return false; + } + + + bool res = this->writer->save(file_path); + + if (res) + this->filePath = file_path; + else + this->close(); + + return res; + } + + + bool FileWriterBodiesClass::writeData(const t_Bodies *bodies) + { + if (!this->writer->isInUse()) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"File not initialized"); + return false; + } + + //get bodies node + Node *bodiesNode = this->writer->getChildFromRoot("bodies"); + + if (bodiesNode == NULL) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get bodies node"); + return false; + } + + + //Add bodies + TimeManagerClass *timeMgr = TimeManagerClass::getInstance(); + + //init iso pattern + string isoPattern = timeMgr->getPatternFromTimeId("iso-mls-z"); + timeMgr->setCurrentPattern(isoPattern.c_str()); + + //typedef t_Bodies::iterator tBdIter; + for (unsigned int i=0;isize();i++) { + ns4__Body* body = bodies->at(i); + ns4__TimeRange* coverage = body->coverage; + t_Time lBodyStart; + t_Time lBodyStop; + if(!timeMgr->from_TIMESTAMP(coverage->startTime, lBodyStart)) { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot convert "<name.c_str()<< " start time"); + return false; + } + if(!timeMgr->from_TIMESTAMP(coverage->stopTime, lBodyStop)) { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot convert "<name.c_str()<< " stop time"); + return false; + } + + Node *bodyNode = this->writer->addChildToNode("body", bodiesNode); + string strId; + stringstream strstr; + strstr << body->naifId; + + //itoa(body->naifId,buff,10); + this->writer->addAttributeToNode("id", strstr.str().c_str(), bodyNode); + //this->writer->setNodeContent(strstr.str().c_str(), this->writer->addChildToNode("id", bodyNode)); + this->writer->setNodeContent(body->name.c_str(), this->writer->addChildToNode("fullname", bodyNode)); + this->writer->setNodeContent(timeMgr->to_PATTERN(lBodyStart).c_str(), this->writer->addChildToNode("startTime", bodyNode)); + this->writer->setNodeContent(timeMgr->to_PATTERN(lBodyStop).c_str(), this->writer->addChildToNode("endTime", bodyNode)); + + } + + + return true; + } + + bool FileWriterBodiesClass::save(void) + { + if (!this->writer->isInUse()) + return false; + + bool res = this->writer->save(this->filePath.c_str()); + + /*if (res) + { + //check xsd validity + if (!this->writer->isValid(TREPS_VOTABLE_XSD)) + { + LOG4CXX_INFO(this->app->getLog()->getPtr(),"The generated VOTable is not valid!"); + } + }*/ + + return res; + } + + bool FileWriterBodiesClass::close(void) + { + if (this->writer->isInUse()) + { + this->writer->close(); + this->filePath = ""; + } + + return !this->writer->isInUse(); + } + + bool FileWriterBodiesClass::isOpened(void) + { + return this->writer->isInUse(); + } + } +} diff --git a/server/kernel/src/File/FileWriterBodies.h b/server/kernel/src/File/FileWriterBodies.h new file mode 100644 index 0000000..cc760e9 --- /dev/null +++ b/server/kernel/src/File/FileWriterBodies.h @@ -0,0 +1,57 @@ +#ifndef FILEWRITERBODIES_H +#define FILEWRITERBODIES_H + +//#define TREPS_VOTABLE_XSD "votable-V1.2.xsd" + +//#include "FileWriterAbstract.h" +//#include +//#include +#include "../XMLManager/XMLManager.h" +#include "../../CDPP3DViewSOAPClient/cdpp3dviewcdppBinderProxy.h" + +using namespace TREPS::XMLManager; + +namespace TREPS +{ + namespace File + { + //declare stype as in Bodies/BodiesCDPP3DView.h + typedef vector t_Bodies; + + class FileWriterBodiesClass + { + public : + FileWriterBodiesClass(void); + + ~FileWriterBodiesClass(void); + + //create XML file and add general attributes + bool init(const char *file_path, const map *attributes); + + //write bodies in xml file + bool writeData(const t_Bodies *bodies); + + //save the XML file + bool save(void); + + //close the xml file + bool close(void); + + //test if a file is opened + bool isOpened(void); + + protected : + ApplicationClass *app; + + private : + //path to the initialized file + string filePath; + + //pointer to the xml writer + XMLManagerClass *writer; + + }; + } +} + +#endif diff --git a/server/kernel/src/RequestManager/RequestBodiesGet.cpp b/server/kernel/src/RequestManager/RequestBodiesGet.cpp new file mode 100644 index 0000000..4f22455 --- /dev/null +++ b/server/kernel/src/RequestManager/RequestBodiesGet.cpp @@ -0,0 +1,163 @@ +#include "RequestBodiesGet.h" + +#include "../Bodies/BodiesCDPP3DView.h" +#include "../Common/Toolbox.h" +#include "../TimeManager/TimeManager.h" + +using namespace TREPS::Common; +using namespace TREPS::Bodies; +using namespace TREPS::TimeManager; + +namespace TREPS +{ + namespace RequestManager + { + RequestBodiesGetClass::RequestBodiesGetClass(void):RequestAbstractClass(), startTime(), stopTime() + { + this->outputType = OUTPUT_XMLFILE; + } + + RequestBodiesGetClass::~RequestBodiesGetClass(void) + { + } + + string RequestBodiesGetClass::getRequestId(void) + { + return "bodies_get"; + } + + bool RequestBodiesGetClass::load(RequestLoaderClass *loader) + { + //init request and lock workind dir where we will generate result file + if (!this->initOpId(loader,true)) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get op Id"); + return false; + } + + //get isSc + string isSc = loader->getArgStrByName("issc"); + if(isSc.compare("true")==0) { + this->isSc = true; + } else { + this->isSc = false; + } + LOG4CXX_INFO(this->app->getLog()->getPtr(),"RequestBodiesGetClass found isSc "<isSc); + //get start time + string startTime = loader->getArgStrByName("starttime"); + //get end time + string stopTime = loader->getArgStrByName("stoptime"); + + + //get time manager instance + TimeManagerClass *timeMgr = TimeManagerClass::getInstance(); + + string pattern = timeMgr->detectPattern(startTime.c_str()); + timeMgr->setCurrentPattern(pattern.c_str()); + timeMgr->from_PATTERN(startTime.c_str(),this->startTime,false); + timeMgr->from_PATTERN(stopTime.c_str(),this->stopTime,false); + + + LOG4CXX_INFO(this->app->getLog()->getPtr(),"RequestBodiesGetClass converted start and stop "<getPatternFromTimeId("iso-mls-z"); + timeMgr->setCurrentPattern(isoPattern.c_str()); + + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"RequestBodiesGet init getBodies"); + if (!getBodies->init(this->isSc, &(this->startTime),&(this->stopTime))) + { + this->lastMsg = getBodies->getLastError(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to init transformation request"); + return false; + } + + //get bodies + bool res = getBodies->run(); + + if (!res) + { + this->lastMsg = getBodies->getLastError(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error during get Bodies between "<to_PATTERN(this->startTime).c_str()<<" and "<to_PATTERN(this->stopTime).c_str()); + } else { + + + //get working dir + string dirPath = this->dirMgr->createNewDir(false); + if (dirPath.compare("") == 0) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error create dir path"); + return false; + } + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"Got dirPath: "<filePath += getPathCorrection(this->app->getConf()->getWorkingDirPath().c_str()); + this->filePath += getPathCorrection(dirPath.c_str()); + this->filePath += "bodiesList.xml"; + + //LOG4CXX_INFO(this->app->getLog()->getPtr(),"*** RequestBodiesGet writer to file "<filePath.c_str()); + + if (this->filePath.compare("") == 0) + { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to get bodies result file path"); + return false; + } + + getBodies->writeResult(this->filePath.c_str()); + } + + //this->success = res; + delete getBodies; + + return res; + + } + + void RequestBodiesGetClass::writeResult(ResultWriterClass *writer) + { + //No result file for this request + } + + string RequestBodiesGetClass::getResultFileSuffix(void) + { + return ""; + } + + string RequestBodiesGetClass::getXMLFilePath(void) + { + return this->filePath; + } + + string RequestBodiesGetClass::getStringResult(void) + { + return ""; + } + } +} diff --git a/server/kernel/src/RequestManager/RequestBodiesGet.h b/server/kernel/src/RequestManager/RequestBodiesGet.h new file mode 100644 index 0000000..d29e91d --- /dev/null +++ b/server/kernel/src/RequestManager/RequestBodiesGet.h @@ -0,0 +1,51 @@ +#ifndef REQUESTBODIESGET_H +#define REQUESTBODIESGET_H + +#include "RequestAbstract.h" + +namespace TREPS +{ + namespace RequestManager + { + class RequestBodiesGetClass : public RequestAbstractClass + { + public: + RequestBodiesGetClass(void); + + ~RequestBodiesGetClass(void); + + //return request id + string getRequestId(void); + + //load request inputs + bool load(RequestLoaderClass *loader); + + //run request + bool run(void); + + //write request result + void writeResult(ResultWriterClass *writer); + + //get suffix used for result file + string getResultFileSuffix(void); + + //get path to result XML file + string getXMLFilePath(void); + + //get string result + string getStringResult(void); + + private: + + t_Time startTime; + t_Time stopTime; + bool isSc; + string filePath; + string lastMsg; + + }; + + } +} + +#endif diff --git a/server/kernel/src/RequestManager/RequestManager.cpp b/server/kernel/src/RequestManager/RequestManager.cpp index d0ec645..fc78a05 100644 --- a/server/kernel/src/RequestManager/RequestManager.cpp +++ b/server/kernel/src/RequestManager/RequestManager.cpp @@ -5,6 +5,7 @@ #include "RequestResetOp.h" #include "RequestSourceInfo.h" #include "RequestSourceGet.h" +#include "RequestBodiesGet.h" #include "RequestFramesGet.h" #include "RequestRunOp.h" #include "RequestResultInfo.h" @@ -75,6 +76,8 @@ namespace TREPS this->request = new RequestSourceInfoClass(); else if (typeStr.compare("source_get") == 0) this->request = new RequestSourceGetClass(); + else if (typeStr.compare("bodies_get") == 0) + this->request = new RequestBodiesGetClass(); else if (typeStr.compare("frames_get") == 0) this->request = new RequestFramesGetClass(); else if (typeStr.compare("run_op") == 0) diff --git a/server/kernel/src/RequestManager/RequestRunOp.cpp b/server/kernel/src/RequestManager/RequestRunOp.cpp index 24d1c62..fb7d10e 100644 --- a/server/kernel/src/RequestManager/RequestRunOp.cpp +++ b/server/kernel/src/RequestManager/RequestRunOp.cpp @@ -12,8 +12,8 @@ namespace TREPS { namespace RequestManager { - RequestRunOpClass::RequestRunOpClass(void):RequestAbstractClass(), srcFrame(""), dstFrame(""), vectorsDef(""), timeFieldId(""), - timeFormatId(""), timePattern(""), success(false), lastMsg("") + RequestRunOpClass::RequestRunOpClass(void):RequestAbstractClass(), srcFrame(""), dstFrame(""), srcCenter(""), dstCenter(""), + vectorsDef(""), timeFieldId(""), timeFormatId(""), timePattern(""), success(false), lastMsg("") { } @@ -37,12 +37,28 @@ namespace TREPS return false; } + //get start time + string startTime = loader->getArgStrByName("starttime"); + //get end time + string stopTime = loader->getArgStrByName("stoptime"); + + + //get time manager instance + TimeManagerClass *timeMgr = TimeManagerClass::getInstance(); + + string pattern = timeMgr->detectPattern(startTime.c_str()); + timeMgr->setCurrentPattern(pattern.c_str()); + timeMgr->from_PATTERN(startTime.c_str(),this->startTime,false); + timeMgr->from_PATTERN(stopTime.c_str(),this->stopTime,false); + //get source frame this->srcFrame = loader->getArgStrByName("srcframe"); - //get destination frame this->dstFrame = loader->getArgStrByName("dstframe"); + + + //test frames. if ((this->srcFrame.compare("") == 0) && (this->dstFrame.compare("") != 0)) { @@ -56,6 +72,28 @@ namespace TREPS return false; } + + /**** For RTN frames ***********/ + //get source center + this->srcCenter = loader->getArgStrByName("srccenter"); + //get destination center + this->dstCenter = loader->getArgStrByName("dstcenter"); + + if(this->srcFrame.compare("RTN")==0 || this->srcFrame.compare("RTP")==0) { + if(srcCenter.compare("")==0) { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get source center for RTP/RTN frame."); + return false; + } + //get TimeFile from atoi(srcCenter.c_str()) + } + if(this->dstFrame.compare("RTN")==0 || this->dstFrame.compare("RTP")==0) { + if(dstCenter.compare("")==0) { + LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get destination center for RTP/RTN frame."); + return false; + } + //get TimeFile from atoi(dstCenter.c_str()) + } + bool noTrans = (this->srcFrame.compare(this->dstFrame) == 0); //get vectors definition @@ -123,7 +161,9 @@ namespace TREPS //init transformation engine TransformationAbstractClass *trans = new TransformationCDPP3DViewClass(this); - if (!trans->init(this->srcFrame.c_str(), this->dstFrame.c_str(), this->vectorsDef.c_str(), + if (!trans->init(this->srcFrame.c_str(), this->dstFrame.c_str(), + this->srcCenter.c_str(), this->dstCenter.c_str(), this->startTime, this->stopTime, + this->vectorsDef.c_str(), this->timeFieldId.c_str(), this->timeFormatId.c_str(), this->timePattern.c_str(), sourcePath.c_str(), requestPath.c_str())) { diff --git a/server/kernel/src/RequestManager/RequestRunOp.h b/server/kernel/src/RequestManager/RequestRunOp.h index b1926e6..b6b5d89 100644 --- a/server/kernel/src/RequestManager/RequestRunOp.h +++ b/server/kernel/src/RequestManager/RequestRunOp.h @@ -40,8 +40,13 @@ namespace TREPS private : string srcFrame; - string dstFrame; + + //for RTN/RTP + string srcCenter; + string dstCenter; + t_Time startTime; + t_Time stopTime; string vectorsDef; diff --git a/server/kernel/src/Transformation/TransformationAbstract.cpp b/server/kernel/src/Transformation/TransformationAbstract.cpp index afbaef0..892cff6 100644 --- a/server/kernel/src/Transformation/TransformationAbstract.cpp +++ b/server/kernel/src/Transformation/TransformationAbstract.cpp @@ -41,7 +41,8 @@ namespace TREPS } } - bool TransformationAbstractClass::init(const char *srcFrame, const char *dstFrame, const char *srcVecDef, + bool TransformationAbstractClass::init(const char *srcFrame, const char *dstFrame, const char *srcCenter, const char *dstCenter, + const t_Time startTime, const t_Time stopTime, const char *srcVecDef, const char *timeFieldId, const char *timeFormatId, const char *timePattern, const char *srcDataFile, const char *transformationRequest) { @@ -69,6 +70,9 @@ namespace TREPS } this->request->setFrames(srcFrame, dstFrame); + this->request->setCenters(srcCenter,dstCenter); + this->request->setTimes(startTime,stopTime); + //load src data if (!this->request->loadSrcData(srcDataFile)) diff --git a/server/kernel/src/Transformation/TransformationAbstract.h b/server/kernel/src/Transformation/TransformationAbstract.h index 58c57d4..19ac210 100644 --- a/server/kernel/src/Transformation/TransformationAbstract.h +++ b/server/kernel/src/Transformation/TransformationAbstract.h @@ -26,7 +26,8 @@ namespace TREPS virtual ~TransformationAbstractClass(void) = 0; //init request - bool init(const char *srcFrame, const char *dstFrame, const char *srcVecDef, + bool init(const char *srcFrame, const char *dstFrame, const char *srcCenter, const char *dstCenter, + const t_Time startTime, const t_Time stopTime, const char *srcVecDef, const char *timeFieldId, const char *timeFormatId, const char *timePattern, const char *srcDataFile, const char *transformationRequest); diff --git a/server/kernel/src/Transformation/TransformationCDPP3DView.cpp b/server/kernel/src/Transformation/TransformationCDPP3DView.cpp index f695729..aa5a95e 100644 --- a/server/kernel/src/Transformation/TransformationCDPP3DView.cpp +++ b/server/kernel/src/Transformation/TransformationCDPP3DView.cpp @@ -1,6 +1,7 @@ #include "TransformationCDPP3DView.h" #include +#include #include "../../CDPP3DViewSOAPClient/cdppBinder.nsmap" @@ -99,6 +100,45 @@ namespace TREPS vectorStatus += intToStr(crtIndex + 1); vectorStatus += " / "; vectorStatus += intToStr(nbSrcVectors); + + //if RTN/RTP, get files + vector timeFiles; + //get time manager instance + TimeManagerClass *timeMgr = TimeManagerClass::getInstance(); + time_t lStart = timeMgr->to_TIMESTAMP(request->getStartTime()); + time_t lStop = timeMgr->to_TIMESTAMP(request->getStopTime()); + + LOG4CXX_INFO(this->app->getLog()->getPtr(),"Search for RTN/RTP " << request->getSrcFrame().c_str()<< "/"<getDstFrame().c_str()); + + + if(request->getSrcFrame().compare("RTN")==0||request->getSrcFrame().compare("RTP")==0){ + LOG4CXX_INFO(this->app->getLog()->getPtr(),"Search for src timeFile for RTN/RTP "<getSrcCenter().c_str()); + istringstream iss(request->getSrcCenter()); + vector splitStr((istream_iterator(iss)),istream_iterator()); + if(splitStr.size()!=4) { + this->errorMsg = "Source frame center should be 4 elements: "; + this->errorMsg += request->getSrcCenter().c_str(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + return false; + } + LOG4CXX_INFO(this->app->getLog()->getPtr(),"Found src sc: "<getDstFrame().compare("RTN")==0||request->getDstFrame().compare("RTP")==0){ + LOG4CXX_INFO(this->app->getLog()->getPtr(),"Search for dst timeFile for RTN/RTP "<getDstCenter().c_str()); + istringstream iss(request->getDstCenter()); + vector splitStr((istream_iterator(iss)),istream_iterator()); + if(splitStr.size()!=4) { + this->errorMsg = "Dest frame center should be 4 elements: "; + this->errorMsg += request->getDstCenter().c_str(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + return false; + } + LOG4CXX_INFO(this->app->getLog()->getPtr(),"Found dst sc: "<trepsRequest->setStatus(generalStatus.c_str()); - url = this->callNewFrameRequest(&(*it), url.c_str()); + url = this->callNewFrameRequest(&(*it), url.c_str(),timeFiles); #else string generalStatus = vectorStatus; generalStatus += " - Running step : Compute transformation"; this->trepsRequest->setStatus(generalStatus.c_str()); - string url = this->callNewFrameRequest(&(*it)); + string url = this->callNewFrameRequest(&(*it),timeFiles); #endif @@ -265,11 +305,68 @@ namespace TREPS { this->availableFrames.push_back((*it)->name); } + //add dynamic frames + this->availableFrames.push_back("RTN"); + this->availableFrames.push_back("RTP"); } return true; } + ns4__TimeFile* TransformationCDPP3DViewClass::callListFilesRequest(int bodyId, time_t startTime, time_t stopTime) + { + bool res = false; + + + string method = "listFiles"; + + //Init 3DView listBodies request + _ns3__listFiles listFilesRequest; + //_ns3__listNewFrameOrb listNewFrameOrbRequest; + //listNewFrameOrbRequest.pUrlInput = NULL; + //listNewFrameOrbRequest.pDateTimeInput = this->createTimeList(); + //listNewFrameOrbRequest.pInFrame = this->request->getSrcFrame(); + //listNewFrameOrbRequest.pOutFrame = this->request->getDstFrame(); + ns4__TimeFileType type = ns4__TimeFileType__ORBIT; + listFilesRequest.type = &type; + listFilesRequest.pBodyId = bodyId; + listFilesRequest.pStartTime = startTime; + listFilesRequest.pStopTime = stopTime; + + //run listNewFrameOrb to perform transformation (rotation + translation) + //_ns3__listNewFrameOrbResponse listNewFrameOrbResponse; + ns4__TimeFileArray listFilesResponse; + res = (this->client->listFiles(&listFilesRequest,&listFilesResponse) == SOAP_OK); + LOG4CXX_INFO(this->app->getLog()->getPtr(),"found timefiles" << listFilesResponse.timeFile.size()); + if(res && listFilesResponse.timeFile.size()>0) { + return listFilesResponse.timeFile.at(0); + } else { + res = false; + } + + + if (!res) + { + this->errorMsg = "Error during the call of "; + this->errorMsg += method; + this->errorMsg += " of 3DView Web Service"; + if (this->client->soap_fault_string() != NULL) + { + this->errorMsg += " ("; + this->errorMsg += this->client->soap_fault_string(); + this->errorMsg += ")"; + } + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + + } + + return NULL; + } + + + + + #ifdef WITH_GETORBURL string TransformationCDPP3DViewClass::callGetOrbUrlRequest(const t_Vector *crtSrcVec) { @@ -311,9 +408,9 @@ namespace TREPS #endif #ifdef WITH_GETORBURL - string TransformationCDPP3DViewClass::callNewFrameRequest(const t_Vector *crtSrcVec, const char *dataURL) + string TransformationCDPP3DViewClass::callNewFrameRequest(const t_Vector *crtSrcVec, const char *dataURL, vector timeFiles) #else - string TransformationCDPP3DViewClass::callNewFrameRequest(const t_Vector *crtSrcVec) + string TransformationCDPP3DViewClass::callNewFrameRequest(const t_Vector *crtSrcVec, vector timeFiles) #endif { bool res = false; @@ -340,6 +437,10 @@ namespace TREPS #endif listNewFrameOrbRequest.pInFrame = this->request->getSrcFrame(); listNewFrameOrbRequest.pOutFrame = this->request->getDstFrame(); + //for RTN/RTP + listNewFrameOrbRequest.pInCenter = this->request->getSrcCenter(); + listNewFrameOrbRequest.pOutCenter = this->request->getDstCenter(); + listNewFrameOrbRequest.pTimeFiles = timeFiles; //run listNewFrameOrb to perform transformation (rotation + translation) _ns3__listNewFrameOrbResponse listNewFrameOrbResponse; @@ -372,6 +473,10 @@ namespace TREPS #endif listNewFrameAttRequest.pInFrame = this->request->getSrcFrame(); listNewFrameAttRequest.pOutFrame = this->request->getDstFrame(); + //for RTN/RTP + listNewFrameAttRequest.pInCenter = this->request->getSrcCenter(); + listNewFrameAttRequest.pOutCenter = this->request->getDstCenter(); + listNewFrameAttRequest.pTimeFiles = timeFiles; //run listNewFrameAtt to perform transformation (rotation) _ns3__listNewFrameAttResponse listNewFrameAttResponse; diff --git a/server/kernel/src/Transformation/TransformationCDPP3DView.h b/server/kernel/src/Transformation/TransformationCDPP3DView.h index af015d1..741ab57 100644 --- a/server/kernel/src/Transformation/TransformationCDPP3DView.h +++ b/server/kernel/src/Transformation/TransformationCDPP3DView.h @@ -62,11 +62,14 @@ namespace TREPS #ifdef WITH_GETORBURL string callGetOrbUrlRequest(const t_Vector *crtSrcVec); - string callNewFrameRequest(const t_Vector *crtSrcVec, const char *dataURL); + string callNewFrameRequest(const t_Vector *crtSrcVec, const char *dataURL, vector timeFiles); #else - string callNewFrameRequest(const t_Vector *crtSrcVec); + string callNewFrameRequest(const t_Vector *crtSrcVec, vector timeFiles); #endif + + ns4__TimeFile* callListFilesRequest(int bodyId, time_t startTime, time_t stopTime); + //get response string getURLResponse(const char *response); diff --git a/server/kernel/src/Transformation/TransformationRequest.cpp b/server/kernel/src/Transformation/TransformationRequest.cpp index 43fb842..228ff06 100644 --- a/server/kernel/src/Transformation/TransformationRequest.cpp +++ b/server/kernel/src/Transformation/TransformationRequest.cpp @@ -14,7 +14,7 @@ namespace TREPS { namespace Transformation { - TransformationRequestClass::TransformationRequestClass(void) : srcFrame(""), dstFrame(""), timeFieldId(""), timeFormat(TF_NONE), timePattern("") + TransformationRequestClass::TransformationRequestClass(void) : srcFrame(""), dstFrame(""), srcCenter(""), dstCenter(""), startTime(), stopTime(), timeFieldId(""), timeFormat(TF_NONE), timePattern("") { this->srcVectors.clear(); this->srcData.clear(); @@ -50,6 +50,40 @@ namespace TREPS return this->dstFrame; } + void TransformationRequestClass::setCenters(const char *srcCenter, const char *dstCenter) + { + this->srcCenter = srcCenter; + this->dstCenter = dstCenter; + } + + string TransformationRequestClass::getSrcCenter(void) const + { + return this->srcCenter; + } + + string TransformationRequestClass::getDstCenter(void) const + { + return this->dstCenter; + } + + void TransformationRequestClass::setTimes(const t_Time startTime, const t_Time stopTime) + { + this->startTime = startTime; + this->stopTime = stopTime; + } + + t_Time TransformationRequestClass::getStartTime(void) const + { + return this->startTime; + } + + t_Time TransformationRequestClass::getStopTime(void) const + { + return this->stopTime; + } + + + bool TransformationRequestClass::setSrcVectorsDefinition(const char *srcVecDef, const char *srcFrame) { this->srcVectors.clear(); diff --git a/server/kernel/src/Transformation/TransformationRequest.h b/server/kernel/src/Transformation/TransformationRequest.h index b811ba4..832874a 100644 --- a/server/kernel/src/Transformation/TransformationRequest.h +++ b/server/kernel/src/Transformation/TransformationRequest.h @@ -30,6 +30,25 @@ namespace TREPS //get transformation destination frame string getDstFrame(void) const; + //set transformation centers for RTN/RTP frames + void setCenters(const char *srcCenter, const char *dstCenter); + + //get transformation source center + string getSrcCenter(void) const; + + //get transformation destination center + string getDstCenter(void) const; + + //set times + void setTimes(const t_Time startTime, const t_Time stopTime); + + //get start time + t_Time getStartTime(void) const; + //get end time + t_Time getStopTime(void) const; + + + //set source vectors defintiion bool setSrcVectorsDefinition(const char *srcVecDef, const char *srcFrame); @@ -72,6 +91,10 @@ namespace TREPS private : string srcFrame; string dstFrame; + string srcCenter; + string dstCenter; + t_Time startTime; + t_Time stopTime; t_VectorList srcVectors; diff --git a/server/php/direct/classes/TREPSAction.php b/server/php/direct/classes/TREPSAction.php index 3c6a4b7..b7fd671 100644 --- a/server/php/direct/classes/TREPSAction.php +++ b/server/php/direct/classes/TREPSAction.php @@ -54,7 +54,7 @@ function runOperation($arg) { $reqMgr = new RequestManager(); - $res = $reqMgr->run('run_op',array('id' => $arg->id, 'srcframe' => $arg->srcframe, 'dstframe' => $arg->dstframe, 'vectors' => $arg->vectors, 'timefieldid' => $arg->timefieldid, 'timeformatid' => $arg->timeformatid, 'timepattern' => $arg->timepattern), OutputTypeEnum::OUTPUT_RESULTFILE); + $res = $reqMgr->run('run_op',array('id' => $arg->id, 'srcframe' => $arg->srcframe,'srccenter' => $arg->srccenter, 'dstframe' => $arg->dstframe, 'dstcenter' => $arg->dstcenter, 'starttime' => $arg->starttime, 'stoptime' => $arg->stoptime, 'vectors' => $arg->vectors, 'timefieldid' => $arg->timefieldid, 'timeformatid' => $arg->timeformatid, 'timepattern' => $arg->timepattern), OutputTypeEnum::OUTPUT_RESULTFILE); return $res; } @@ -100,6 +100,13 @@ return $res; } + function getBodiesList($arg) + { + $reqMgr = new RequestManager(); + $res = $reqMgr->run('bodies_get',array('id' => $arg->id, 'issc' => $arg->issc, 'starttime' => $arg->starttime, 'stoptime' => $arg->stoptime),OutputTypeEnum::OUTPUT_XMLFILE); + return $res; + } + function getFramesList() { $reqMgr = new RequestManager(); diff --git a/server/php/direct/config.php b/server/php/direct/config.php index 915e65f..28d189f 100644 --- a/server/php/direct/config.php +++ b/server/php/direct/config.php @@ -32,6 +32,9 @@ $API = array( 'getRunInfo'=>array( 'len'=>1 ), + 'getBodiesList'=>array( + 'len'=>1 + ), 'getFramesList'=>array( 'len'=>1 ), -- libgit2 0.21.2