def __init__(self, viewer=None): """Constructor """ BaseModeLogic.__init__(self) # setting new logic for a sheet if viewer already exists if viewer is not None: self.__viewer = viewer sheet = self.__viewer._getSheet() if sheet is None: raise RuntimeError("There is no sheet") else: self.__viewer = SCgViewer() self.mergeModes(self.__viewer) self.appendMode(ois.KC_E, scg_modes.SCgEditMode(self)) self.switchMode(ois.KC_E)
def __init__(self, viewer = None): """Constructor """ BaseModeLogic.__init__(self) # setting new logic for a sheet if viewer already exists if viewer is not None: self.__viewer = viewer sheet = self.__viewer._getSheet() if sheet is None: raise RuntimeError("There is no sheet") else: self.__viewer = SCgViewer() self.mergeModes(self.__viewer) self.appendMode(ois.KC_E, scg_modes.SCgEditMode(self)) self.switchMode(ois.KC_E)
class SCgEditor(BaseModeLogic): """Logic realization of SCg-editor. To synchronize this object we use transaction model. Each transaction applies in update method. That guarantee ogre calls in one graphical thread. """ def __init__(self, viewer = None): """Constructor """ BaseModeLogic.__init__(self) # setting new logic for a sheet if viewer already exists if viewer is not None: self.__viewer = viewer sheet = self.__viewer._getSheet() if sheet is None: raise RuntimeError("There is no sheet") else: self.__viewer = SCgViewer() self.mergeModes(self.__viewer) self.appendMode(ois.KC_E, scg_modes.SCgEditMode(self)) self.switchMode(ois.KC_E) def __del__(self): """Destructor """ BaseModeLogic.__del__(self) def delete(self): """Deletion message """ BaseModeLogic.delete(self) if self.__viewer: self.__viewer.delete() def __getattr__(self, _name): """Returning attributes that exists in viewer to unify calling from modes """ return getattr(self.__viewer, _name) def _setSheet(self, _sheet): """Notification about sheet changed for logic @param _sheet: sheet object logic sets to @type _sheet: ObjectSheet @attention: this method only for internal usage and calls by ObhectSheet automatically when you set logic for it """ self.__viewer._setSheet(_sheet) BaseModeLogic._setSheet(self, _sheet) _sheet.eventUpdateView = self._onUpdateView _sheet.eventUpdate = self._onUpdate _sheet.eventRootChanged = self._onRootChanged _sheet.eventSelectionChanged = self._modes[ois.KC_E]._handlerSelChanged def _onUpdate(self, _dt): """Update sheet event @param _dt: time since last frame @type _dt: float """ if self._active_mode is not None: self._active_mode._update(_dt) def _onUpdateView(self): """Update sheet view event """ pass def _onRootChanged(self, _isRoot): """Root state changed event @param _isRoot: new root state @type _isRoot: bool """ BaseModeLogic._onRootChanged(self, _isRoot) if _isRoot: render_engine.SceneManager.setBackMaterial("Back/Lime") else: self.__viewer.makeNewScreenshot() render_engine.SceneManager.setDefaultBackMaterial() def _createNode(self, _pos, _type = "node/const/elem"): """Creates node in specified position @param _pos: position tuple (x,y) @type _pos: tuple @param _type: node type @type _type: str @return: created node """ node = scg_alphabet.createSCgNode(_type) node.setState(objects.Object.OS_Normal) sheet = self._getSheet() sheet.addChild(node) if render_engine.viewMode == render_engine.Mode_Isometric: node.setPosition(render_engine.pos2dTo3dIsoPos(_pos)) else: # raise RuntimeError("Not implemented 3d mode in scg editor") node.setPosition(render_engine.pos2dToViewPortRay(_pos).getPoint(25.0)) return node def _createPair(self, _beg, _end, _type = "pair/pos/-/orient/const"): """Creates pair with begin and end. @param _beg: begin object @type _beg: object.Object @param _end: end object @type _end: object.Object @param _type: pair type @type _type: str @return: created pair """ pair = scg_alphabet.createSCgPair(_type) sheet = self._getSheet() sheet.addChild(pair) pair.setBegin(_beg) pair.setEnd(_end) pair.setState(objects.Object.OS_Normal) return pair def _createContour(self, points): """Create contour """ contour = scg_alphabet.createContour() sheet = self._getSheet() sheet.addChild(contour) contour.setPoints(points) contour.setState(objects.Object.OS_Normal)
class SCgEditor(BaseModeLogic): """Logic realization of SCg-editor. To synchronize this object we use transaction model. Each transaction applies in update method. That guarantee ogre calls in one graphical thread. """ def __init__(self, viewer=None): """Constructor """ BaseModeLogic.__init__(self) # setting new logic for a sheet if viewer already exists if viewer is not None: self.__viewer = viewer sheet = self.__viewer._getSheet() if sheet is None: raise RuntimeError("There is no sheet") else: self.__viewer = SCgViewer() self.mergeModes(self.__viewer) self.appendMode(ois.KC_E, scg_modes.SCgEditMode(self)) self.switchMode(ois.KC_E) def __del__(self): """Destructor """ BaseModeLogic.__del__(self) def delete(self): """Deletion message """ BaseModeLogic.delete(self) if self.__viewer: self.__viewer.delete() def __getattr__(self, _name): """Returning attributes that exists in viewer to unify calling from modes """ return getattr(self.__viewer, _name) def _setSheet(self, _sheet): """Notification about sheet changed for logic @param _sheet: sheet object logic sets to @type _sheet: ObjectSheet @attention: this method only for internal usage and calls by ObhectSheet automatically when you set logic for it """ self.__viewer._setSheet(_sheet) BaseModeLogic._setSheet(self, _sheet) _sheet.eventUpdateView = self._onUpdateView _sheet.eventUpdate = self._onUpdate _sheet.eventRootChanged = self._onRootChanged _sheet.eventSelectionChanged = self._modes[ois.KC_E]._handlerSelChanged def _onUpdate(self, _dt): """Update sheet event @param _dt: time since last frame @type _dt: float """ if self._active_mode is not None: self._active_mode._update(_dt) def _onUpdateView(self): """Update sheet view event """ pass def _onRootChanged(self, _isRoot): """Root state changed event @param _isRoot: new root state @type _isRoot: bool """ BaseModeLogic._onRootChanged(self, _isRoot) if _isRoot: render_engine.SceneManager.setBackMaterial("Back/Lime") else: self.__viewer.makeNewScreenshot() render_engine.SceneManager.setDefaultBackMaterial() def _createNode(self, _pos, _type="node/const/elem"): """Creates node in specified position @param _pos: position tuple (x,y) @type _pos: tuple @param _type: node type @type _type: str @return: created node """ node = scg_alphabet.createSCgNode(_type) node.setState(objects.Object.OS_Normal) sheet = self._getSheet() sheet.addChild(node) if render_engine.viewMode == render_engine.Mode_Isometric: node.setPosition(render_engine.pos2dTo3dIsoPos(_pos)) else: # raise RuntimeError("Not implemented 3d mode in scg editor") node.setPosition( render_engine.pos2dToViewPortRay(_pos).getPoint(25.0)) return node def _createPair(self, _beg, _end, _type="pair/pos/-/orient/const"): """Creates pair with begin and end. @param _beg: begin object @type _beg: object.Object @param _end: end object @type _end: object.Object @param _type: pair type @type _type: str @return: created pair """ pair = scg_alphabet.createSCgPair(_type) sheet = self._getSheet() sheet.addChild(pair) pair.setBegin(_beg) pair.setEnd(_end) pair.setState(objects.Object.OS_Normal) return pair def _createContour(self, points): """Create contour """ contour = scg_alphabet.createContour() sheet = self._getSheet() sheet.addChild(contour) contour.setPoints(points) contour.setState(objects.Object.OS_Normal) def _createBus(self, _beg, _end_pos): """Create bus @param _beg: begin object @type _beg: object.Object @param _end_pos: end position @type _end_pos: tuple @return: created bus """ bus = scg_alphabet.createBus() sheet = self._getSheet() sheet.addChild(bus) bus.setAttachedNode(_beg) bus.setEndPointPos(_end_pos) bus.setState(objects.Object.OS_Normal) return bus