def state_from_chain_piece(self, chain_piece):

        cp = chain_piece
        self.lan_chain_session_id = cp.lan_chain.session_id
        from SessionUtil.stateclasses import Xform_State
        xfs = Xform_State()
        xfs.state_from_xform(cp.xform)
        self.xform_state = xfs
        if hasattr(cp.xform, 'id_number'):
            self.xform_id_number = cp.xform.id_number
        self.surface_shown = cp.surface_shown()
        self.rgba = cp.color()
        g = cp.surface_piece
        if g:
            (self.surface_resolution, self.density_threshold,
             self.smoothing_factor,
             self.smoothing_iterations) = g.surfacing_parameters
        else:
            self.surface_resolution = None
            self.density_threshold = None
            self.smoothing_factor = None
            self.smoothing_iterations = None

        if cp.surf_model:
            from SessionUtil.stateclasses import Model_State
            sms = Model_State()
            sms.state_from_model(cp.surf_model)
            self.surface_model_state = sms
        else:
            self.surface_model_state = None
Beispiel #2
0
  def state_from_chain_piece(self, chain_piece):

      cp = chain_piece
      self.lan_chain_session_id = cp.lan_chain.session_id
      from SessionUtil.stateclasses import Xform_State
      xfs = Xform_State()
      xfs.state_from_xform(cp.xform)
      self.xform_state = xfs
      if hasattr(cp.xform, 'id_number'):
        self.xform_id_number = cp.xform.id_number
      self.surface_shown = cp.surface_shown()
      self.rgba = cp.color()
      g = cp.surface_piece
      if g:
          (self.surface_resolution,
           self.density_threshold,
           self.smoothing_factor,
           self.smoothing_iterations) = g.surfacing_parameters
      else:
          self.surface_resolution = None
          self.density_threshold = None
          self.smoothing_factor = None
          self.smoothing_iterations = None

      if cp.surf_model:
          from SessionUtil.stateclasses import Model_State
          sms = Model_State()
          sms.state_from_model(cp.surf_model)
          self.surface_model_state = sms
      else:
          self.surface_model_state = None
Beispiel #3
0
  def state_from_group_piece(self, group_piece):
    
      gp = group_piece
  
      self.name = gp.name
      self.children_states = model_piece_states(gp.children)

      if gp.surf_model:
          from SessionUtil.stateclasses import Model_State
          sms = Model_State()
          sms.state_from_model(gp.surf_model)
          self.surface_model_state = sms
      else:
          self.surface_model_state = None
    def state_from_group_piece(self, group_piece):

        gp = group_piece

        self.name = gp.name
        self.children_states = model_piece_states(gp.children)

        if gp.surf_model:
            from SessionUtil.stateclasses import Model_State
            sms = Model_State()
            sms.state_from_model(gp.surf_model)
            self.surface_model_state = sms
        else:
            self.surface_model_state = None
Beispiel #5
0
    def state_from_marker_set(self, marker_set):

        ms = marker_set
        self.name = ms.name

        if ms.molecule:
            from SessionUtil.stateclasses import Model_State
            self.marker_model = Model_State()
            self.marker_model.state_from_model(ms.molecule)
            from SimpleSession import sessionID
            self.molecule_session_id = sessionID(ms.molecule)
            self.color = ms.molecule.color.rgba()
        else:
            self.marker_model = None
            self.molecule_session_id = None
            self.color = None

        if ms.curve_model:
            from SessionUtil.stateclasses import Model_State
            cm = Model_State()
            cm.state_from_model(ms.curve_model)
            self.curve_parameters = ms.curve_parameters
            self.curve_model = cm
        else:
            self.curve_model = None
            self.curve_parameters = None

        self.next_marker_id = ms.next_marker_id
        self.file_path = ms.file_path

        self.markers = []
        for m in ms.markers():
            s = Marker_State()
            s.state_from_marker(m)
            self.markers.append(s)

        self.links = []
        for l in ms.links():
            s = Link_State()
            s.state_from_link(l)
            self.links.append(s)

        if hasattr(ms, 'extra_attribtues'):  # from reading XML
            self.extra_attributes = ms.extra_attributes
        else:
            self.extra_attributes = None
Beispiel #6
0
  def state_from_marker_set(self, marker_set):

    ms = marker_set
    self.name = ms.name

    if ms.molecule:
      from SessionUtil.stateclasses import Model_State
      self.marker_model = Model_State()
      self.marker_model.state_from_model(ms.molecule)
      from SimpleSession import sessionID
      self.molecule_session_id = sessionID(ms.molecule)
      self.color = ms.molecule.color.rgba()
    else:
      self.marker_model = None
      self.molecule_session_id = None
      self.color = None

    if ms.curve_model:
      from SessionUtil.stateclasses import Model_State
      cm = Model_State()
      cm.state_from_model(ms.curve_model)
      self.curve_parameters = ms.curve_parameters
      self.curve_model = cm
    else:
      self.curve_model = None
      self.curve_parameters = None

    self.next_marker_id = ms.next_marker_id
    self.file_path = ms.file_path

    self.markers = []
    for m in ms.markers():
      s = Marker_State()
      s.state_from_marker(m)
      self.markers.append(s)

    self.links = []
    for l in ms.links():
      s = Link_State()
      s.state_from_link(l)
      self.links.append(s)

    if hasattr(ms, 'extra_attribtues'):		# from reading XML
      self.extra_attributes = ms.extra_attributes
    else:
      self.extra_attributes = None
Beispiel #7
0
    def state_from_surface_model(self, sm, plist):

        self.name = sm.name

        from SessionUtil.stateclasses import Model_State
        ms = Model_State()
        ms.state_from_model(sm)
        self.surface_model = ms

        self.pieces_are_selectable = sm.piecesAreSelectable
        self.one_transparent_layer = sm.oneTransparentLayer

        splist = []
        for p in plist:
            sp = Surface_Piece_State()
            sp.state_from_surface_piece(p)
            splist.append(sp)
        self.surface_piece_states = splist
Beispiel #8
0
  def state_from_surface_model(self, sm, plist):

    self.name = sm.name

    from SessionUtil.stateclasses import Model_State
    ms = Model_State()
    ms.state_from_model(sm)
    self.surface_model = ms

    self.pieces_are_selectable = sm.piecesAreSelectable
    self.one_transparent_layer = sm.oneTransparentLayer

    splist = []
    for p in plist:
      sp = Surface_Piece_State()
      sp.state_from_surface_piece(p)
      splist.append(sp)
    self.surface_piece_states = splist
Beispiel #9
0
    def state_from_marker_set(self, marker_set):

        ms = marker_set
        self.name = ms.name

        if ms.marker_molecule:
            from SessionUtil.stateclasses import Model_State

            self.marker_model = Model_State()
            self.marker_model.state_from_model(ms.marker_molecule)
        else:
            self.marker_model = None

        if ms.curve_model:
            from SessionUtil.stateclasses import Model_State

            cm = Model_State()
            cm.state_from_model(ms.curve_model)
            self.curve_parameters = ms.curve_parameters
            self.curve_model = cm
        else:
            self.curve_model = None
            self.curve_parameters = None

        self.next_marker_id = ms.next_marker_id
        self.file_path = ms.file_path

        self.markers = []
        for m in ms.atom_to_marker.values():
            s = Marker_State()
            s.state_from_marker(m)
            self.markers.append(s)

        self.links = []
        for l in ms.bond_to_link.values():
            s = Link_State()
            s.state_from_link(l)
            self.links.append(s)

        if hasattr(ms, "extra_attribtues"):  # from reading XML
            self.extra_attributes = ms.extra_attributes
        else:
            self.extra_attributes = None
Beispiel #10
0
class Scale_Bar_Dialog_State:

  version = 1
  
  state_attributes = ('is_visible',
                      'geometry',
		      'show_scalebar',
		      'bar_length',
		      'bar_thickness',
		      'bar_rgba',
		      'label_text',
		      'label_x_offset',
		      'label_y_offset',
		      'label_rgba',
		      'orientation',
		      'preserve_position',
		      'screen_x_position',
		      'screen_y_position',
		      'move_scalebar',
		      'frozen_models',
		      'model',
		      'version',
                      )
  
  # ---------------------------------------------------------------------------
  #
  def state_from_dialog(self, scale_bar_dialog):

    d = scale_bar_dialog

    self.is_visible = d.isVisible()
    self.geometry = d.toplevel_widget.wm_geometry()

    self.show_scalebar = d.show_scalebar.get()
    self.bar_length = d.bar_length.get()
    self.bar_thickness = d.bar_thickness.get()
    self.bar_rgba = d.bar_color.rgba
    self.label_text = d.label_text.get()
    self.label_x_offset = d.label_x_offset.get()
    self.label_y_offset = d.label_y_offset.get()
    self.label_rgba = d.label_color.rgba
    self.orientation = d.orientation.get()
    self.preserve_position = d.preserve_position.get()
    self.screen_x_position = d.screen_x_position.get()
    self.screen_y_position = d.screen_y_position.get()
    self.move_scalebar = d.move_scalebar.get()
    self.frozen_models = map(lambda m: (m.id, m.subid), d.frozen_models())

    if d.model:
      from SessionUtil.stateclasses import Model_State
      self.model = Model_State()
      self.model.state_from_model(d.model)
    else:
      self.model = None

  # ---------------------------------------------------------------------------
  #
  def restore_state(self, scale_bar_dialog):

    d = scale_bar_dialog
    if self.is_visible:
      d.enter()
    d.toplevel_widget.wm_geometry(self.geometry)
    d.toplevel_widget.wm_geometry('')		# restore standard size

    d.show_scalebar.set(self.show_scalebar, invoke_callbacks = 0)
    d.bar_length.set(self.bar_length, invoke_callbacks = 0)
    d.bar_thickness.set(self.bar_thickness, invoke_callbacks = 0)
    d.bar_color.showColor(self.bar_rgba, doCallback = 0)
    d.label_text.set(self.label_text, invoke_callbacks = 0)
    d.label_x_offset.set(self.label_x_offset, invoke_callbacks = 0)
    d.label_y_offset.set(self.label_y_offset, invoke_callbacks = 0)
    d.label_color.showColor(self.label_rgba, doCallback = 0)
    d.orientation.set(self.orientation, invoke_callbacks = 0)
    d.preserve_position.set(self.preserve_position, invoke_callbacks = 0)
    d.screen_x_position.set(self.screen_x_position, invoke_callbacks = 0)
    d.screen_y_position.set(self.screen_y_position, invoke_callbacks = 0)
    d.move_scalebar.set(self.move_scalebar, invoke_callbacks = 0)
    m = self.model
    if m:
      from SimpleSession import modelOffset
      model_id = (m.id + modelOffset, m.subid)
    else:
      model_id = None
    d.settings_changed_cb(model_id = model_id)

    if self.frozen_models:
      from SimpleSession import registerAfterModelsCB
      registerAfterModelsCB(self.restore_frozen_models, scale_bar_dialog)

    if m:
      m.restore_state(d.model)

    if m:
      from SimpleSession import registerAfterModelsCB
      registerAfterModelsCB(self.restore_screen_position, scale_bar_dialog)
      registerAfterModelsCB(self.fix_stick_scale, scale_bar_dialog)
      
  # ---------------------------------------------------------------------------
  #
  def restore_frozen_models(self, scale_bar_dialog):

    frozen_models = []
    if self.frozen_models:
      if isinstance(self.frozen_models[0], basestring):
        from SimpleSession import oslMap
        model_ids = []
        for id in self.frozen_models:
          try:
            new_id = oslMap(id)
          except:
            new_id = id
          model_ids.append(new_id)

        id_to_model = {}
        import chimera
        for m in chimera.openModels.list(all = 1):
          id_to_model[m.oslIdent()] = m

        for id in model_ids:
          if id_to_model.has_key(id):
            frozen_models.append(id_to_model[id])
      else:
        from SimpleSession import modelMap
        for id in self.frozen_models:
          frozen_models.extend(modelMap.get(id, []))
    scale_bar_dialog.frozen_model_list = frozen_models
      
  # ---------------------------------------------------------------------------
  # SimpleSession changes the scale bar xform when the camera has not yet
  # been reset causing the preserved scale bar screen position to change.
  # This restores the screen position after that happens.
  #
  def restore_screen_position(self, scale_bar_dialog):

    d = scale_bar_dialog
    if d.model:
      d.screen_x_position.set(self.screen_x_position, invoke_callbacks = 0)
      d.screen_y_position.set(self.screen_y_position, invoke_callbacks = 0)
      t = d.model.openState.xform.getTranslation()
      d.last_xyz_position = (t.x, t.y, t.z)
      d.settings_changed_cb()
      
  # ---------------------------------------------------------------------------
  # SimpleSession changes the stickScale setting when Chimera 1.1700
  # session files are opened in Chimera >1.18xx.  This resets it to 1.
  #
  def fix_stick_scale(self, scale_bar_dialog):

    d = scale_bar_dialog
    if d.model:
      d.model.stickScale = 1.0
Beispiel #11
0
class Marker_Set_State:

    version = 3

    state_attributes = (
        'name',
        'marker_model',
        'molecule_session_id',
        'color',
        'curve_model',
        'curve_parameters',
        'next_marker_id',
        'file_path',
        'markers',
        'links',
        'extra_attributes',
        'version',
    )

    # ---------------------------------------------------------------------------
    #
    def state_from_marker_set(self, marker_set):

        ms = marker_set
        self.name = ms.name

        if ms.molecule:
            from SessionUtil.stateclasses import Model_State
            self.marker_model = Model_State()
            self.marker_model.state_from_model(ms.molecule)
            from SimpleSession import sessionID
            self.molecule_session_id = sessionID(ms.molecule)
            self.color = ms.molecule.color.rgba()
        else:
            self.marker_model = None
            self.molecule_session_id = None
            self.color = None

        if ms.curve_model:
            from SessionUtil.stateclasses import Model_State
            cm = Model_State()
            cm.state_from_model(ms.curve_model)
            self.curve_parameters = ms.curve_parameters
            self.curve_model = cm
        else:
            self.curve_model = None
            self.curve_parameters = None

        self.next_marker_id = ms.next_marker_id
        self.file_path = ms.file_path

        self.markers = []
        for m in ms.markers():
            s = Marker_State()
            s.state_from_marker(m)
            self.markers.append(s)

        self.links = []
        for l in ms.links():
            s = Link_State()
            s.state_from_link(l)
            self.links.append(s)

        if hasattr(ms, 'extra_attribtues'):  # from reading XML
            self.extra_attributes = ms.extra_attributes
        else:
            self.extra_attributes = None

    # ---------------------------------------------------------------------------
    #
    def create_object(self):

        import markerset
        ms = markerset.Marker_Set(self.name)

        ms.next_marker_id = self.next_marker_id
        ms.file_path = self.file_path

        mm = self.marker_model
        if mm:
            if self.version >= 3:
                from SimpleSession import idLookup
                m = idLookup(self.molecule_session_id)
                ms.set_marker_molecule(m)
                import markerset
                markerset.msc.open_models_cb(None, None, [m])
            else:
                from SimpleSession import modelOffset
                model_id = (mm.id + modelOffset, mm.subid)
                m = ms.marker_model(model_id)
            if self.version >= 2:
                m.color = markerset.chimera_color(self.color)

        id_to_marker = {}
        for m in self.markers:
            marker = m.create_object(ms)
            id_to_marker[marker.id] = marker

        for l in self.links:
            l.create_object(id_to_marker)

        if self.extra_attributes:
            ms.extra_attributes = self.extra_attributes

        if mm and ms.molecule:
            mm.restore_state(ms.molecule)

        cm = self.curve_model
        if cm:
            radius, band_length, subdivisions = self.curve_parameters
            ms.show_curve(radius, band_length, subdivisions)
            cm.restore_state(ms.curve_model)

        return ms
Beispiel #12
0
class Marker_Set_State:
  
  version = 3

  state_attributes = ('name',
		      'marker_model',
                      'molecule_session_id',
                      'color',
		      'curve_model',
		      'curve_parameters',
		      'next_marker_id',
		      'file_path',
		      'markers',
		      'links',
		      'extra_attributes',
		      'version',
		      )

  # ---------------------------------------------------------------------------
  #
  def state_from_marker_set(self, marker_set):

    ms = marker_set
    self.name = ms.name

    if ms.molecule:
      from SessionUtil.stateclasses import Model_State
      self.marker_model = Model_State()
      self.marker_model.state_from_model(ms.molecule)
      from SimpleSession import sessionID
      self.molecule_session_id = sessionID(ms.molecule)
      self.color = ms.molecule.color.rgba()
    else:
      self.marker_model = None
      self.molecule_session_id = None
      self.color = None

    if ms.curve_model:
      from SessionUtil.stateclasses import Model_State
      cm = Model_State()
      cm.state_from_model(ms.curve_model)
      self.curve_parameters = ms.curve_parameters
      self.curve_model = cm
    else:
      self.curve_model = None
      self.curve_parameters = None

    self.next_marker_id = ms.next_marker_id
    self.file_path = ms.file_path

    self.markers = []
    for m in ms.markers():
      s = Marker_State()
      s.state_from_marker(m)
      self.markers.append(s)

    self.links = []
    for l in ms.links():
      s = Link_State()
      s.state_from_link(l)
      self.links.append(s)

    if hasattr(ms, 'extra_attribtues'):		# from reading XML
      self.extra_attributes = ms.extra_attributes
    else:
      self.extra_attributes = None

  # ---------------------------------------------------------------------------
  #
  def create_object(self):

    import markerset
    ms = markerset.Marker_Set(self.name)

    ms.next_marker_id = self.next_marker_id
    ms.file_path = self.file_path

    mm = self.marker_model
    if mm:
      if self.version >= 3:
        from SimpleSession import idLookup
        m = idLookup(self.molecule_session_id)
        ms.set_marker_molecule(m)
        import markerset
        markerset.msc.open_models_cb(None, None, [m])
      else:
        from SimpleSession import modelOffset
        model_id = (mm.id + modelOffset, mm.subid)
        m = ms.marker_model(model_id)
      if self.version >= 2:
        m.color = markerset.chimera_color(self.color)

    id_to_marker = {}
    for m in self.markers:
      marker = m.create_object(ms)
      id_to_marker[marker.id] = marker

    for l in self.links:
      l.create_object(id_to_marker)

    if self.extra_attributes:
      ms.extra_attributes = self.extra_attributes

    if mm and ms.molecule:
      mm.restore_state(ms.molecule)

    cm = self.curve_model
    if cm:
      radius, band_length, subdivisions = self.curve_parameters
      ms.show_curve(radius, band_length, subdivisions)
      cm.restore_state(ms.curve_model)

    return ms
class Scale_Bar_Dialog_State:

    version = 1

    state_attributes = (
        'is_visible',
        'geometry',
        'show_scalebar',
        'bar_length',
        'bar_thickness',
        'bar_rgba',
        'label_text',
        'label_x_offset',
        'label_y_offset',
        'label_rgba',
        'orientation',
        'preserve_position',
        'screen_x_position',
        'screen_y_position',
        'move_scalebar',
        'frozen_models',
        'model',
        'version',
    )

    # ---------------------------------------------------------------------------
    #
    def state_from_dialog(self, scale_bar_dialog):

        d = scale_bar_dialog

        self.is_visible = d.isVisible()
        self.geometry = d.toplevel_widget.wm_geometry()

        self.show_scalebar = d.show_scalebar.get()
        self.bar_length = d.bar_length.get()
        self.bar_thickness = d.bar_thickness.get()
        self.bar_rgba = d.bar_color.rgba
        self.label_text = d.label_text.get()
        self.label_x_offset = d.label_x_offset.get()
        self.label_y_offset = d.label_y_offset.get()
        self.label_rgba = d.label_color.rgba
        self.orientation = d.orientation.get()
        self.preserve_position = d.preserve_position.get()
        self.screen_x_position = d.screen_x_position.get()
        self.screen_y_position = d.screen_y_position.get()
        self.move_scalebar = d.move_scalebar.get()
        self.frozen_models = map(lambda m: (m.id, m.subid), d.frozen_models())

        if d.model:
            from SessionUtil.stateclasses import Model_State
            self.model = Model_State()
            self.model.state_from_model(d.model)
        else:
            self.model = None

    # ---------------------------------------------------------------------------
    #
    def restore_state(self, scale_bar_dialog):

        d = scale_bar_dialog
        if self.is_visible:
            d.enter()
        d.toplevel_widget.wm_geometry(self.geometry)
        d.toplevel_widget.wm_geometry('')  # restore standard size

        d.show_scalebar.set(self.show_scalebar, invoke_callbacks=0)
        d.bar_length.set(self.bar_length, invoke_callbacks=0)
        d.bar_thickness.set(self.bar_thickness, invoke_callbacks=0)
        d.bar_color.showColor(self.bar_rgba, doCallback=0)
        d.label_text.set(self.label_text, invoke_callbacks=0)
        d.label_x_offset.set(self.label_x_offset, invoke_callbacks=0)
        d.label_y_offset.set(self.label_y_offset, invoke_callbacks=0)
        d.label_color.showColor(self.label_rgba, doCallback=0)
        d.orientation.set(self.orientation, invoke_callbacks=0)
        d.preserve_position.set(self.preserve_position, invoke_callbacks=0)
        d.screen_x_position.set(self.screen_x_position, invoke_callbacks=0)
        d.screen_y_position.set(self.screen_y_position, invoke_callbacks=0)
        d.move_scalebar.set(self.move_scalebar, invoke_callbacks=0)
        m = self.model
        if m:
            from SimpleSession import modelOffset
            model_id = (m.id + modelOffset, m.subid)
        else:
            model_id = None
        d.settings_changed_cb(model_id=model_id)

        if self.frozen_models:
            from SimpleSession import registerAfterModelsCB
            registerAfterModelsCB(self.restore_frozen_models, scale_bar_dialog)

        if m:
            m.restore_state(d.model)

        if m:
            from SimpleSession import registerAfterModelsCB
            registerAfterModelsCB(self.restore_screen_position,
                                  scale_bar_dialog)
            registerAfterModelsCB(self.fix_stick_scale, scale_bar_dialog)

    # ---------------------------------------------------------------------------
    #
    def restore_frozen_models(self, scale_bar_dialog):

        frozen_models = []
        if self.frozen_models:
            if isinstance(self.frozen_models[0], basestring):
                from SimpleSession import oslMap
                model_ids = []
                for id in self.frozen_models:
                    try:
                        new_id = oslMap(id)
                    except:
                        new_id = id
                    model_ids.append(new_id)

                id_to_model = {}
                import chimera
                for m in chimera.openModels.list(all=1):
                    id_to_model[m.oslIdent()] = m

                for id in model_ids:
                    if id_to_model.has_key(id):
                        frozen_models.append(id_to_model[id])
            else:
                from SimpleSession import modelMap
                for id in self.frozen_models:
                    frozen_models.extend(modelMap.get(id, []))
        scale_bar_dialog.frozen_model_list = frozen_models

    # ---------------------------------------------------------------------------
    # SimpleSession changes the scale bar xform when the camera has not yet
    # been reset causing the preserved scale bar screen position to change.
    # This restores the screen position after that happens.
    #
    def restore_screen_position(self, scale_bar_dialog):

        d = scale_bar_dialog
        if d.model:
            d.screen_x_position.set(self.screen_x_position, invoke_callbacks=0)
            d.screen_y_position.set(self.screen_y_position, invoke_callbacks=0)
            t = d.model.openState.xform.getTranslation()
            d.last_xyz_position = (t.x, t.y, t.z)
            d.settings_changed_cb()

    # ---------------------------------------------------------------------------
    # SimpleSession changes the stickScale setting when Chimera 1.1700
    # session files are opened in Chimera >1.18xx.  This resets it to 1.
    #
    def fix_stick_scale(self, scale_bar_dialog):

        d = scale_bar_dialog
        if d.model:
            d.model.stickScale = 1.0
Beispiel #14
0
class Marker_Set_State:

    version = 1

    state_attributes = (
        "name",
        "marker_model",
        "curve_model",
        "curve_parameters",
        "next_marker_id",
        "file_path",
        "markers",
        "links",
        "extra_attributes",
        "version",
    )

    # ---------------------------------------------------------------------------
    #
    def state_from_marker_set(self, marker_set):

        ms = marker_set
        self.name = ms.name

        if ms.marker_molecule:
            from SessionUtil.stateclasses import Model_State

            self.marker_model = Model_State()
            self.marker_model.state_from_model(ms.marker_molecule)
        else:
            self.marker_model = None

        if ms.curve_model:
            from SessionUtil.stateclasses import Model_State

            cm = Model_State()
            cm.state_from_model(ms.curve_model)
            self.curve_parameters = ms.curve_parameters
            self.curve_model = cm
        else:
            self.curve_model = None
            self.curve_parameters = None

        self.next_marker_id = ms.next_marker_id
        self.file_path = ms.file_path

        self.markers = []
        for m in ms.atom_to_marker.values():
            s = Marker_State()
            s.state_from_marker(m)
            self.markers.append(s)

        self.links = []
        for l in ms.bond_to_link.values():
            s = Link_State()
            s.state_from_link(l)
            self.links.append(s)

        if hasattr(ms, "extra_attribtues"):  # from reading XML
            self.extra_attributes = ms.extra_attributes
        else:
            self.extra_attributes = None

    # ---------------------------------------------------------------------------
    #
    def create_object(self):

        import markerset

        ms = markerset.Marker_Set(self.name)

        ms.next_marker_id = self.next_marker_id
        ms.file_path = self.file_path

        id_to_marker = {}
        for m in self.markers:
            marker = m.create_object(ms)
            id_to_marker[marker.id] = marker

        for l in self.links:
            l.create_object(id_to_marker)

        if self.extra_attributes:
            ms.extra_attributes = self.extra_attributes

        if self.marker_model and ms.marker_molecule:
            self.marker_model.restore_state(ms.marker_molecule)

        cm = self.curve_model
        if cm:
            radius, band_length, subdivisions = self.curve_parameters
            ms.show_curve(radius, band_length, subdivisions)
            cm.restore_state(ms.curve_model)

        return ms
Beispiel #15
0
class Icosahedron_Dialog_State:

  version = 1
  
  state_attributes = ('is_visible',
                      'geometry',
		      'radius',
		      'sphere_factor',
		      'orientation',
		      'subdivision_factor',
                      'style',
                      'color',
                      'surface_model',
		      'version',
                      )
  
  # ---------------------------------------------------------------------------
  #
  def state_from_dialog(self, icosahedron_dialog):

    d = icosahedron_dialog

    self.is_visible = d.isVisible()
    t = d.uiMaster().winfo_toplevel()
    self.geometry = t.wm_geometry()

    self.radius = d.radius.value(d.default_radius)
    self.sphere_factor = d.sphere_factor.value(0)
    self.orientation = d.orientation.get()
    from CGLtk import Hybrid
    self.subdivision_factor = Hybrid.float_variable_value(d.subdivision_factor,
                                                          1)
    self.style = d.surface_style.get()
    self.color = d.color.rgba

    if d.surface_model is None:
      self.surface_model = None
    else:
      from SessionUtil.stateclasses import Model_State
      self.surface_model = Model_State()
      self.surface_model.state_from_model(d.surface_model)

  # ---------------------------------------------------------------------------
  #
  def restore_state(self, icosahedron_dialog):

    d = icosahedron_dialog
    if self.is_visible:
      d.enter()

    t = d.uiMaster().winfo_toplevel()
    t.wm_geometry(self.geometry)
    t.wm_geometry('')		# restore standard size

    d.radius.set_value(self.radius, invoke_callbacks = False)
    d.sphere_factor.set_value(self.sphere_factor, invoke_callbacks = False)
    d.orientation.set(self.orientation, invoke_callbacks = False)
    d.subdivision_factor.set(self.subdivision_factor, invoke_callbacks = False)
    d.surface_style.set(self.style, invoke_callbacks = False)
    d.color.showColor(self.color, doCallback = False)

    sms = self.surface_model
    if not sms is None:
      from SimpleSession import modelOffset
      d.show_cb(model_id = (sms.id + modelOffset, sms.subid))
      sms.restore_state(d.surface_model)
Beispiel #16
0
class Icosahedron_Dialog_State:

    version = 1

    state_attributes = (
        'is_visible',
        'geometry',
        'radius',
        'sphere_factor',
        'orientation',
        'subdivision_factor',
        'style',
        'color',
        'surface_model',
        'version',
    )

    # ---------------------------------------------------------------------------
    #
    def state_from_dialog(self, icosahedron_dialog):

        d = icosahedron_dialog

        self.is_visible = d.isVisible()
        t = d.uiMaster().winfo_toplevel()
        self.geometry = t.wm_geometry()

        self.radius = d.radius.value(d.default_radius)
        self.sphere_factor = d.sphere_factor.value(0)
        self.orientation = d.orientation.get()
        from CGLtk import Hybrid
        self.subdivision_factor = Hybrid.float_variable_value(
            d.subdivision_factor, 1)
        self.style = d.surface_style.get()
        self.color = d.color.rgba

        if d.surface_model is None:
            self.surface_model = None
        else:
            from SessionUtil.stateclasses import Model_State
            self.surface_model = Model_State()
            self.surface_model.state_from_model(d.surface_model)

    # ---------------------------------------------------------------------------
    #
    def restore_state(self, icosahedron_dialog):

        d = icosahedron_dialog
        if self.is_visible:
            d.enter()

        t = d.uiMaster().winfo_toplevel()
        t.wm_geometry(self.geometry)
        t.wm_geometry('')  # restore standard size

        d.radius.set_value(self.radius, invoke_callbacks=False)
        d.sphere_factor.set_value(self.sphere_factor, invoke_callbacks=False)
        d.orientation.set(self.orientation, invoke_callbacks=False)
        d.subdivision_factor.set(self.subdivision_factor,
                                 invoke_callbacks=False)
        d.surface_style.set(self.style, invoke_callbacks=False)
        d.color.showColor(self.color, doCallback=False)

        sms = self.surface_model
        if not sms is None:
            from SimpleSession import modelOffset
            d.show_cb(model_id=(sms.id + modelOffset, sms.subid))
            sms.restore_state(d.surface_model)