From 9d42cb67c174056ada8ca5e9c335af61ad14c3ff Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 22 Oct 2015 10:28:40 +0300 Subject: [PATCH] Make services.py and roots.py more PEP8 complience and add reset() function --- src/PythonAPI/model/roots.py | 51 +++++++++-------- src/PythonAPI/model/services.py | 99 +++++++++++++++++++-------------- 2 files changed, 86 insertions(+), 64 deletions(-) diff --git a/src/PythonAPI/model/roots.py b/src/PythonAPI/model/roots.py index 62288ebb3..117840e47 100644 --- a/src/PythonAPI/model/roots.py +++ b/src/PythonAPI/model/roots.py @@ -3,39 +3,44 @@ Author: Daniel Brunier-Coulin Copyright (C) 2014-20xx CEA/DEN, EDF R&D """ -from ModelAPI import * +import ModelAPI -class Feature(ModelAPI_Feature): - """Base class of user-defined Python features.""" - def __init__(self): - ModelAPI_Feature.__init__(self) +class Feature(ModelAPI.ModelAPI_Feature): + """Base class of user-defined Python features.""" - def addRealInput (self, inputid): - self.data().addAttribute(inputid, ModelAPI_AttributeDouble_typeId()) + def __init__(self): + ModelAPI.ModelAPI_Feature.__init__(self) - def getRealInput (self, inputid): - return self.data().real(inputid).value() + def addRealInput (self, inputid): + self.data().addAttribute(inputid, + ModelAPI.ModelAPI_AttributeDouble_typeId()) - def addResult (self, result): - shape = result.shape() - body = self.document().createBody( self.data() ) - body.store(shape) - self.setResult(body) + def getRealInput (self, inputid): + return self.data().real(inputid).value() + + def addResult (self, result): + shape = result.shape() + body = self.document().createBody(self.data()) + body.store(shape) + self.setResult(body) class Interface(): - """Base class of hight level Python interfaces to features.""" + """Base class of hight level Python interfaces to features.""" + + def __init__(self, feature): + self._feature = feature + - def __init__(self, container, fid): - self.my = container.addFeature(fid) - def setRealInput (self, inputid, value): - self.my.data().real(inputid).setValue(value) + def setRealInput (self, inputid, value): + self._feature.data().real(inputid).setValue(value) - def areInputValid (self): - return ModelAPI_Session.get().validators().validate(self.my) + def areInputValid (self): + validators = ModelAPI.ModelAPI_Session.get().validators() + return validators.validate(self._feature) - def execute (self): - self.my.execute() \ No newline at end of file + def execute (self): + self._feature.execute() diff --git a/src/PythonAPI/model/services.py b/src/PythonAPI/model/services.py index d463c5951..962087bcf 100644 --- a/src/PythonAPI/model/services.py +++ b/src/PythonAPI/model/services.py @@ -3,70 +3,87 @@ Author: Daniel Brunier-Coulin Copyright (C) 2014-20xx CEA/DEN, EDF R&D """ -from ModelAPI import * -from GeomAPI import * -import geom # To be removed when gp_Ax3 will be Pythonized +import ModelAPI +import GeomAPI + +import geom # To be removed when gp_Ax3 will be Pythonized def moduleDocument (): - """Returns the main document (the Partset) created or open from the Modeler. - This document is unique in the application session. - """ - return ModelAPI_Session.get().moduleDocument() + """Return the main document (the Partset) created or open from the Modeler. + + This document is unique in the application session. + """ + return ModelAPI.ModelAPI_Session.get().moduleDocument() def activeDocument (): - """Returns the active document. - This document can be either the main application document (i.e. the Partset) or one of documents - referred to by the main document (a Part). - """ - return ModelAPI_Session.get().activeDocument() + """Return the active document. + + This document can be either the main application document (i.e. the Partset) or one of documents + referred to by the main document (a Part). + """ + return ModelAPI.ModelAPI_Session.get().activeDocument() def defaultPlane (name): - """Returns one of the three planes defined by the global coordinate system. - These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0). - """ -# Temporary implementation before the availability of default planes. + """Return one of the three planes defined by the global coordinate system. - o = GeomAPI_Pnt( 0, 0, 0 ) - if name == "XOY": - n = GeomAPI_Dir( 0, 0, 1) - x = GeomAPI_Dir( 1, 0, 0) - elif name == "XOZ": - n = GeomAPI_Dir( 0, 1, 0) - x = GeomAPI_Dir( 1, 0, 0) - elif name == "YOZ": - n = GeomAPI_Dir( 1, 0, 0) - x = GeomAPI_Dir( 0, 1, 0) + These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0). + """ + # Temporary implementation before the availability of default planes. + o = GeomAPI.GeomAPI_Pnt(0, 0, 0) + if name == "XOY": + n = GeomAPI.GeomAPI_Dir(0, 0, 1) + x = GeomAPI.GeomAPI_Dir(1, 0, 0) + elif name == "XOZ": + n = GeomAPI.GeomAPI_Dir(0, 1, 0) + x = GeomAPI.GeomAPI_Dir(1, 0, 0) + elif name == "YOZ": + n = GeomAPI.GeomAPI_Dir(1, 0, 0) + x = GeomAPI.GeomAPI_Dir(0, 1, 0) - return geom.Ax3( o, n, x ) + return geom.Ax3(o, n, x) def begin (): - """Starts a data structure transaction, as such making a control point for being able to discard or undo - all operations done during this transaction. - """ - ModelAPI_Session.get().startOperation() + """Start a data structure transaction. + + Make a control point for being able to discard or undo + all operations done during this transaction. + """ + ModelAPI.ModelAPI_Session.get().startOperation() def end (): - """Commits the data structure transaction and makes all operations done since the last control point undo-able.""" - ModelAPI_Session.get().finishOperation() + """Commit the data structure transaction. + + Make all operations done since the last control point undo-able. + """ + ModelAPI.ModelAPI_Session.get().finishOperation() def do (): - """Commits the data structure transaction and makes all operations done since the last control point undo-able.""" - session = ModelAPI_Session.get() - session.finishOperation() - session.startOperation() + """Commit the data structure transaction and start the new one. + + Make all operations done since the last control point undo-able + and continue with the new transaction. + """ + session = ModelAPI.ModelAPI_Session.get() + session.finishOperation() + session.startOperation() def undo (): - """Rolls-back the data structure to the previous control point.""" - ModelAPI_Session.get().undo() + """Roll-back the data structure to the previous control point.""" + ModelAPI.ModelAPI_Session.get().undo() def redo (): - """Restore the data structure rolled-back by the last undo.""" - ModelAPI_Session.get().redo() + """Restore the data structure rolled-back by the last undo.""" + ModelAPI.ModelAPI_Session.get().redo() + + +def reset (): + """Reset the data structure to initial state.""" + ModelAPI.ModelAPI_Session.get().closeAll() -- 2.39.2