event->eventtype = DatasourceEvent::EVENT_IMPORT_OBJECT;
XmedDataObject * dataObject = new XmedDataObject();
dataObject->setFieldHandler(*duplicate);
- event->objectdata = dataObject;
+ event->objectdata = dataObject;
emit datasourceSignal(event);
// Note that this signal is processed by the WorkspaceController
}
else if ( event->eventtype == DatasourceEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
QStringList commands;
- commands += QString("from medpresentation import MakeScalarMap");
+ commands += QString("from medcalc import MakeScalarMap");
commands += QString("import MEDOP");
#define stringify( name ) # name
}
else if ( event->eventtype == DatasourceEvent::EVENT_ADD_DATASOURCE ) {
QStringList commands;
- commands += QString("from medpresentation import LoadDataSource");
+ commands += QString("from medcalc import LoadDataSource");
commands += QString("LoadDataSource('%1')").arg(event->objectalias);
_consoleDriver->exec(commands);
}
else if ( event->eventtype == DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE ) {
QStringList commands;
- commands += QString("from medpresentation import LoadImageAsDataSource");
+ commands += QString("from medcalc import LoadImageAsDataSource");
commands += QString("LoadImageAsDataSource('%1')").arg(event->objectalias);
_consoleDriver->exec(commands);
}
/*!
* This function sends the specified list of commands to the console.
*/
-void XmedConsoleDriver::exec(QStringList commands) {
+void XmedConsoleDriver::exec(const QStringList& commands) {
QStringListIterator it(commands);
while (it.hasNext()) {
_pyConsole->exec(it.next());
}
+ this->_history.append(commands);
}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Guillaume Boulant (EDF)
+// Author : Guillaume Boulant (EDF)
#ifndef XMEDCONSOLEDRIVER_HXX
#define XMEDCONSOLEDRIVER_HXX
#include "MEDOPGUI.hxx"
+typedef QList<QStringList> CommandsHistory;
+
class MEDOPGUI_EXPORT XmedConsoleDriver {
public:
XmedConsoleDriver(SalomeApp_Application * application);
void setup();
- void exec(QStringList commands);
+ void exec(const QStringList& commands);
+
+ inline const CommandsHistory& getHistory() { return _history; }
private:
PyConsole_Console * _pyConsole;
bool _importXmedDone;
+ CommandsHistory _history;
};
#endif //XMEDCONSOLEDRIVER_HXX
#
ADD_SUBDIRECTORY(xmedpy)
-ADD_SUBDIRECTORY(medpresentation)
+ADD_SUBDIRECTORY(presentation)
+++ /dev/null
-# Copyright (C) 2012-2015 CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-SET(PYFILES_TO_INSTALL
- __init__.py
- medpresentation.py
- xmedimages.py
- )
-
-SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}/medpresentation)
+++ /dev/null
-# Copyright (C) 2011-2015 CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-from medpresentation import LoadDataSource
-from medpresentation import LoadImageAsDataSource
-
-from medpresentation import MakeScalarMap
+++ /dev/null
-# Copyright (C) 2011-2015 CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-import xmed
-import MEDOP
-import SALOME
-
-__manager = xmed.factory.getPresentationManager()
-
-def LoadDataSource(filename):
- xmed.dataManager.loadDatasource(filename)
- from xmed.fieldproxy import notifyGui_addsource
- notifyGui_addsource(filename)
-#
-
-def LoadImageAsDataSource(filename):
- # get temp file name to generate med file from image
- import tempfile
- temp = tempfile.NamedTemporaryFile(suffix='.cfg')
- medfilename = temp.name
- temp.close()
-
- from xmedimages import FieldBuilder
- builder = FieldBuilder()
- builder.image2med(filename, medfilename)
- LoadDataSource(medfilename)
-#
-
-def MakeScalarMap(proxy, viewMode=MEDOP.VIEW_MODE_REPLACE):
- # Create the presentation instance in CORBA engine
- # The engine in turn creates the ParaView pipeline elements
-
- print "In MakeScalarMap (Python)"
-
- print "viewMode:", viewMode, " [", type(viewMode), "]"
-
- params = MEDOP.ScalarMapParameters(proxy.id, viewMode)
- __manager.MakeScalarMap(params)
-
-#
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2015 CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-# Author : Guillaume Boulant (EDF)
-
-import MEDCoupling as MC
-import MEDLoader as ML
-
-from PIL import Image
-from PIL import ImageOps
-import numpy
-
-class FieldBuilder:
-
- def image2med(self, imageFilepath, medFilepath=None):
-
- # Load the image file in a numpy array using PIL.
- img=Image.open(imageFilepath)
- imgbw=ImageOps.grayscale(img)
- # WARN: We keep only the grayscale. Maybe, it could be usefull
- # to get the RGB scales each on one component of the field.
-
- # Creating a cartesian mesh with a grid of the size of the image
- # The sizes defined the number of pixel in a direction, then the
- # number of cells to create in the mesh in that direction.
- width,height=imgbw.size
- mesh=self.createMesh("grid_%sx%s"%(width,height),width,height)
- field=self.createField("imagefield",mesh,imgbw)
-
- # The MEDLoader can be used to save all the stuff in a med file. You
- # just have to specify the field and the MEDLoader will save the
- # underlying mesh.
- createFromScratch=True
- ML.MEDLoader.WriteField(medFilepath,field,createFromScratch)
-
- def createMesh(self, meshname, sizeX, sizeY):
- """
- Creating a cartesian mesh with a grid of the size of the image.
- sizeX and sizeY should be respectively the width and heigth of the
- image.
- """
- # >>>
- # WARNING: remember the problem of tics and spaces. The data values
- # are considered as values defined on cells. With size values in a
- # direction, we have to create size+1 mesh nodes in that direction.
- # <<<
-
- # The mesh is created using MEDCoupling
- cmesh=MC.MEDCouplingCMesh.New();
- cmesh.setName(meshname)
-
- # We use an arbitrary step between cells (the value does not matter)
- stepX = 0.1
- nbNodesX = sizeX+1
- arrX = [float(i * stepX) for i in range(nbNodesX)]
- coordsX=MC.DataArrayDouble.New()
- coordsX.setValues(arrX,nbNodesX,1)
-
- # For the Y dimension, we have to reverse the coordinates (the
- # first pixel is at y=height and not at y=0).
- stepY = 0.1
- nbNodesY = sizeY+1
- lengthY = sizeY*stepY
- arrY=[float(lengthY - i * stepY) for i in range(nbNodesY)]
- coordsY=MC.DataArrayDouble.New()
- coordsY.setValues(arrY,nbNodesY,1)
-
- cmesh.setCoords(coordsX,coordsY)
- print "Imagem mesh dimension: %d"%cmesh.getSpaceDimension()
-
- # WARN: In the current state of development of MEDLoader, only
- # unstructured meshes are supported for writting function in med
- # files. We just have to convert the cartesian mesh in an unstructured
- # mesh before creating the field.
- umesh=cmesh.buildUnstructured();
- umesh.setName(cmesh.getName())
-
- return umesh
-
- def createField(self, fieldname, mesh, image):
- """
- Creating a scalar field on the mesh using image data
- """
- # Create the field using MEDCoupling
- field = MC.MEDCouplingFieldDouble.New(MC.ON_CELLS,MC.ONE_TIME);
- field.setName(fieldname);
- field.setMesh(mesh);
- # OPTIONAL: We set an arbitrary time step for test purpose
- field.setIteration(0);
- field.setOrder(0)
-
- imagedata=list(image.getdata())
- width,height=image.size
- nbCells = width*height
- dataArray=MC.DataArrayDouble.New();
- nbComponents=1 # For a scalar field
-
- dataArray.setValues(imagedata,nbCells,nbComponents)
- field.setArray(dataArray);
-
- return field
-
-#
-# ===================================================================
-# use case functions
-# ===================================================================
-#
-
-def getTestImagePath():
- import os
- MED_ROOT_DIR=os.environ["MED_ROOT_DIR"]
- RESDIR=os.path.join(MED_ROOT_DIR, "share", "salome", "resources", "med", "medop_testfiles")
- imgFileName="irm_test1.png"
- imgFilePath=os.path.join(RESDIR,imgFileName)
- return imgFilePath
-
-def TEST_pil():
- imgFilePath = getTestImagePath()
- img=Image.open(imageFilepath)
- imgbw=ImageOps.grayscale(img)
-
-
-def TEST_image2med():
- imgFilePath = getTestImagePath()
- builder = FieldBuilder()
- builder.image2med(imgFilePath,"image.med")
-
-# ===================================================================
-if __name__ == "__main__":
- TEST_pil()
- #TEST_image2med()
--- /dev/null
+# Copyright (C) 2012-2015 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+SET(PYFILES_TO_INSTALL
+ __init__.py
+ medpresentation.py
+ medimages.py
+ )
+
+SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}/medcalc)
--- /dev/null
+# Copyright (C) 2011-2015 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from medpresentation import LoadDataSource
+from medpresentation import LoadImageAsDataSource
+
+from medpresentation import MakeScalarMap
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+# Author : Guillaume Boulant (EDF)
+
+import MEDCoupling as MC
+import MEDLoader as ML
+
+from PIL import Image
+from PIL import ImageOps
+import numpy
+
+class FieldBuilder:
+
+ def image2med(self, imageFilepath, medFilepath=None):
+
+ # Load the image file in a numpy array using PIL.
+ img=Image.open(imageFilepath)
+ imgbw=ImageOps.grayscale(img)
+ # WARN: We keep only the grayscale. Maybe, it could be usefull
+ # to get the RGB scales each on one component of the field.
+
+ # Creating a cartesian mesh with a grid of the size of the image
+ # The sizes defined the number of pixel in a direction, then the
+ # number of cells to create in the mesh in that direction.
+ width,height=imgbw.size
+ mesh=self.createMesh("grid_%sx%s"%(width,height),width,height)
+ field=self.createField("imagefield",mesh,imgbw)
+
+ # The MEDLoader can be used to save all the stuff in a med file. You
+ # just have to specify the field and the MEDLoader will save the
+ # underlying mesh.
+ createFromScratch=True
+ ML.MEDLoader.WriteField(medFilepath,field,createFromScratch)
+
+ def createMesh(self, meshname, sizeX, sizeY):
+ """
+ Creating a cartesian mesh with a grid of the size of the image.
+ sizeX and sizeY should be respectively the width and heigth of the
+ image.
+ """
+ # >>>
+ # WARNING: remember the problem of tics and spaces. The data values
+ # are considered as values defined on cells. With size values in a
+ # direction, we have to create size+1 mesh nodes in that direction.
+ # <<<
+
+ # The mesh is created using MEDCoupling
+ cmesh=MC.MEDCouplingCMesh.New();
+ cmesh.setName(meshname)
+
+ # We use an arbitrary step between cells (the value does not matter)
+ stepX = 0.1
+ nbNodesX = sizeX+1
+ arrX = [float(i * stepX) for i in range(nbNodesX)]
+ coordsX=MC.DataArrayDouble.New()
+ coordsX.setValues(arrX,nbNodesX,1)
+
+ # For the Y dimension, we have to reverse the coordinates (the
+ # first pixel is at y=height and not at y=0).
+ stepY = 0.1
+ nbNodesY = sizeY+1
+ lengthY = sizeY*stepY
+ arrY=[float(lengthY - i * stepY) for i in range(nbNodesY)]
+ coordsY=MC.DataArrayDouble.New()
+ coordsY.setValues(arrY,nbNodesY,1)
+
+ cmesh.setCoords(coordsX,coordsY)
+ print "Imagem mesh dimension: %d"%cmesh.getSpaceDimension()
+
+ # WARN: In the current state of development of MEDLoader, only
+ # unstructured meshes are supported for writting function in med
+ # files. We just have to convert the cartesian mesh in an unstructured
+ # mesh before creating the field.
+ umesh=cmesh.buildUnstructured();
+ umesh.setName(cmesh.getName())
+
+ return umesh
+
+ def createField(self, fieldname, mesh, image):
+ """
+ Creating a scalar field on the mesh using image data
+ """
+ # Create the field using MEDCoupling
+ field = MC.MEDCouplingFieldDouble.New(MC.ON_CELLS,MC.ONE_TIME);
+ field.setName(fieldname);
+ field.setMesh(mesh);
+ # OPTIONAL: We set an arbitrary time step for test purpose
+ field.setIteration(0);
+ field.setOrder(0)
+
+ imagedata=list(image.getdata())
+ width,height=image.size
+ nbCells = width*height
+ dataArray=MC.DataArrayDouble.New();
+ nbComponents=1 # For a scalar field
+
+ dataArray.setValues(imagedata,nbCells,nbComponents)
+ field.setArray(dataArray);
+
+ return field
+
+#
+# ===================================================================
+# use case functions
+# ===================================================================
+#
+
+def getTestImagePath():
+ import os
+ MED_ROOT_DIR=os.environ["MED_ROOT_DIR"]
+ RESDIR=os.path.join(MED_ROOT_DIR, "share", "salome", "resources", "med", "medop_testfiles")
+ imgFileName="irm_test1.png"
+ imgFilePath=os.path.join(RESDIR,imgFileName)
+ return imgFilePath
+
+def TEST_pil():
+ imgFilePath = getTestImagePath()
+ img=Image.open(imageFilepath)
+ imgbw=ImageOps.grayscale(img)
+
+
+def TEST_image2med():
+ imgFilePath = getTestImagePath()
+ builder = FieldBuilder()
+ builder.image2med(imgFilePath,"image.med")
+
+# ===================================================================
+if __name__ == "__main__":
+ TEST_pil()
+ #TEST_image2med()
--- /dev/null
+# Copyright (C) 2011-2015 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import xmed
+import MEDOP
+import SALOME
+
+__manager = xmed.factory.getPresentationManager()
+
+def LoadDataSource(filename):
+ xmed.dataManager.loadDatasource(filename)
+ from xmed.fieldproxy import notifyGui_addsource
+ notifyGui_addsource(filename)
+#
+
+def LoadImageAsDataSource(filename):
+ # get temp file name to generate med file from image
+ import tempfile
+ temp = tempfile.NamedTemporaryFile(suffix='.cfg')
+ medfilename = temp.name
+ temp.close()
+
+ from medimages import FieldBuilder
+ builder = FieldBuilder()
+ builder.image2med(filename, medfilename)
+ LoadDataSource(medfilename)
+#
+
+def MakeScalarMap(proxy, viewMode=MEDOP.VIEW_MODE_REPLACE):
+ # Create the presentation instance in CORBA engine
+ # The engine in turn creates the ParaView pipeline elements
+
+ print "In MakeScalarMap (Python)"
+
+ print "viewMode:", viewMode, " [", type(viewMode), "]"
+
+ params = MEDOP.ScalarMapParameters(proxy.id, viewMode)
+ __manager.MakeScalarMap(params)
+
+#