Exemple #1
0
    def OnPopupItemSelected(self, event):
        print('OnPopupItemSelected', self.popup_obj)

        # tree_item = event.GetItem()
        # item_data = self.GetItemData(tree_item)

        (node_type, node_main_info, node_extra_info) = self.popup_obj
        OM = ObjectManager()

        if node_type == ID_TYPE_OBJECT:
            print('ID_TYPE_OBJECT remove:', node_main_info)
            OM.remove(node_main_info)

        elif node_type == ID_TYPE_TID:
            # if node_info == 'well':
            #    items = OM.list(node_main_info)
            # else:
            items = OM.list(node_main_info, node_extra_info)
            for item in items:
                print('ID_TYPE_TID remove:', item.uid)

                OM.remove(item.uid)
        print('FIM OnPopupItemSelected')
class RockTable(wx.grid.GridTableBase):
    @debugdecorator
    def __init__(self, rocktableuid):
        super(RockTable, self).__init__()

        self.OM = ObjectManager()
        self.rocktypeuid = []
        self.rocktableuid = rocktableuid

        self.rocktypemap = [
            rocktype.uid
            for rocktype in self.OM.list('rocktype', self.rocktableuid)
        ]
        self.N_COLS = 4
        self.N_ROWS = 0

    @debugdecorator
    def AppendRows(self, numRows=1):
        rocktype = self.GrainEntry()
        #        rocktype = self.OM.new('rocktype')
        rocktype.defaultdata = np.nan
        self.OM.add(rocktype, self.rocktableuid)

        self.rocktypemap.append(rocktype.uid)
        color = self.get_color(0)
        self.set_color(-1, color)

        self.GetView().BeginBatch()
        msg = wx.grid.GridTableMessage(self,
                                       wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED,
                                       numRows)
        self.GetView().ProcessTableMessage(msg)
        self.GetView().EndBatch()

        return True

    @debugdecorator
    def GrainEntry(self):
        UIM = UIManager()
        dlg = UIM.create('dialog_controller', title='Rock creator')
        cont_grain = dlg.view.AddCreateContainer('StaticBox',
                                                 label='Grain Parts',
                                                 orient=wx.VERTICAL,
                                                 proportion=0,
                                                 flag=wx.EXPAND | wx.TOP,
                                                 border=5)
        cont_matr = dlg.view.AddCreateContainer('StaticBox',
                                                label='Matrix Parts',
                                                orient=wx.VERTICAL,
                                                proportion=0,
                                                flag=wx.EXPAND | wx.TOP,
                                                border=5)

        json_file = '\\Temp\\min.json'
        #        fullpath_json = 'C:\\Users\\rtabelini\\Documents\\Github\\GRIPy'+json_file
        fullpath_json = cwd() + json_file

        dictmin = app.app_utils.read_json_file(fullpath_json)

        def on_change_mineral(name, old_value, new_value, **kwargs):
            print('new\n', name, new_value, new_value['name'],
                  dictmin.iterkeys())
            if name == 'mineralgrain':
                textctrl_k = dlg.view.get_object('kmod1')
                textctrl_g = dlg.view.get_object('gmod1')
                textctrl_rho = dlg.view.get_object('dens1')
            elif name == 'mineralmatrix':
                textctrl_k = dlg.view.get_object('kmod2')
                textctrl_g = dlg.view.get_object('gmod2')
                textctrl_rho = dlg.view.get_object('dens2')

            if new_value['name'] in dictmin.iterkeys():
                textctrl_k.set_value(new_value['K'])
                textctrl_g.set_value(new_value['G'])
                textctrl_rho.set_value(new_value['Dens'])

        dlg.view.AddChoice(cont_grain,
                           widget_name='mineralgrain',
                           options=dictmin,
                           flag=wx.EXPAND)
        choice_grain = dlg.view.get_object('mineralgrain')
        choice_grain.set_trigger(on_change_mineral)

        dlg.view.AddChoice(cont_matr,
                           widget_name='mineralmatrix',
                           options=dictmin,
                           flag=wx.EXPAND)
        choice_matrix = dlg.view.get_object('mineralmatrix')
        choice_matrix.set_trigger(on_change_mineral)

        gr_frac = dlg.view.AddCreateContainer('BoxSizer',
                                              cont_grain,
                                              orient=wx.HORIZONTAL,
                                              proportion=1,
                                              flag=wx.EXPAND | wx.ALL,
                                              border=5)
        dlg.view.AddStaticText(gr_frac,
                               proportion=1,
                               initial='Fraction ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(gr_frac,
                             proportion=1,
                             widget_name='frac1',
                             initial='0.8',
                             flag=wx.ALIGN_RIGHT)

        gr_poro = dlg.view.AddCreateContainer('BoxSizer',
                                              cont_grain,
                                              orient=wx.HORIZONTAL,
                                              proportion=1,
                                              flag=wx.EXPAND | wx.ALL,
                                              border=5)
        dlg.view.AddStaticText(gr_poro,
                               proportion=1,
                               initial='Porosity ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(gr_poro,
                             proportion=1,
                             widget_name='poro1',
                             initial='0.20',
                             flag=wx.ALIGN_RIGHT)

        gr_kmod = dlg.view.AddCreateContainer('BoxSizer',
                                              cont_grain,
                                              orient=wx.HORIZONTAL,
                                              proportion=1,
                                              flag=wx.EXPAND | wx.ALL,
                                              border=5)
        dlg.view.AddStaticText(gr_kmod,
                               proportion=1,
                               widget_name='K_Modulus',
                               initial='K Modulus (GPa) ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(gr_kmod,
                             proportion=1,
                             widget_name='kmod1',
                             initial='36.5',
                             flag=wx.ALIGN_RIGHT)

        gr_gmod = dlg.view.AddCreateContainer('BoxSizer',
                                              cont_grain,
                                              orient=wx.HORIZONTAL,
                                              proportion=1,
                                              flag=wx.EXPAND | wx.ALL,
                                              border=5)
        dlg.view.AddStaticText(gr_gmod,
                               proportion=1,
                               widget_name='G_Modulus',
                               initial='G Modulus (GPa) ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(gr_gmod,
                             proportion=1,
                             widget_name='gmod1',
                             initial='78.6',
                             flag=wx.ALIGN_RIGHT)

        gr_dens = dlg.view.AddCreateContainer('BoxSizer',
                                              cont_grain,
                                              orient=wx.HORIZONTAL,
                                              proportion=1,
                                              flag=wx.EXPAND | wx.ALL,
                                              border=5)
        dlg.view.AddStaticText(gr_dens,
                               proportion=1,
                               widget_name='Density',
                               initial='Density (g/cc) ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(gr_dens,
                             proportion=1,
                             widget_name='dens1',
                             initial='2.65',
                             flag=wx.ALIGN_RIGHT)

        mtr_frac = dlg.view.AddCreateContainer('BoxSizer',
                                               cont_matr,
                                               orient=wx.HORIZONTAL,
                                               proportion=1,
                                               flag=wx.EXPAND | wx.ALL,
                                               border=5)
        dlg.view.AddStaticText(mtr_frac,
                               proportion=1,
                               widget_name='fraction2',
                               initial='Fraction ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(mtr_frac,
                             proportion=1,
                             widget_name='frac2',
                             initial='0.2',
                             flag=wx.ALIGN_LEFT)

        mtr_poro = dlg.view.AddCreateContainer('BoxSizer',
                                               cont_matr,
                                               orient=wx.HORIZONTAL,
                                               proportion=1,
                                               flag=wx.EXPAND | wx.ALL,
                                               border=5)
        dlg.view.AddStaticText(mtr_poro,
                               proportion=1,
                               initial='Porosity ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(mtr_poro,
                             proportion=1,
                             widget_name='poro2',
                             initial='0.10',
                             flag=wx.ALIGN_RIGHT)

        mtr_kmod = dlg.view.AddCreateContainer('BoxSizer',
                                               cont_matr,
                                               orient=wx.HORIZONTAL,
                                               proportion=1,
                                               flag=wx.EXPAND | wx.ALL,
                                               border=5)
        dlg.view.AddStaticText(mtr_kmod,
                               proportion=1,
                               widget_name='K_Modulus2',
                               initial='K Modulus (GPa) ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(mtr_kmod,
                             proportion=1,
                             widget_name='kmod2',
                             initial='36.5',
                             flag=wx.ALIGN_LEFT)

        mtr_gmod = dlg.view.AddCreateContainer('BoxSizer',
                                               cont_matr,
                                               orient=wx.HORIZONTAL,
                                               proportion=1,
                                               flag=wx.EXPAND | wx.ALL,
                                               border=5)
        dlg.view.AddStaticText(mtr_gmod,
                               proportion=1,
                               widget_name='G_Modulus2',
                               initial='G Modulus (GPa) ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(mtr_gmod,
                             proportion=1,
                             widget_name='gmod2',
                             initial='78.6',
                             flag=wx.ALIGN_LEFT)

        mtr_dens = dlg.view.AddCreateContainer('BoxSizer',
                                               cont_matr,
                                               orient=wx.HORIZONTAL,
                                               proportion=1,
                                               flag=wx.EXPAND | wx.ALL,
                                               border=5)
        dlg.view.AddStaticText(mtr_dens,
                               proportion=1,
                               widget_name='Density2',
                               initial='Density (g/cc) ',
                               flag=wx.ALIGN_RIGHT)
        dlg.view.AddTextCtrl(mtr_dens,
                             proportion=1,
                             widget_name='dens2',
                             initial='2.65',
                             flag=wx.ALIGN_LEFT)
        #
        try:
            if dlg.view.ShowModal() == wx.ID_OK:
                results = dlg.get_results()
                gr_f = results.get('frac1')
                mtr_f = results.get('frac2')
                ngrain = results.get('mineralgrain')['name']
                nmatrix = results.get('mineralmatrix')['name']
                gr_phi = results.get('poro1')
                gr_k = results.get('kmod1')
                gr_mi = results.get('gmod1')
                gr_rho = results.get('dens1')
                mtr_phi = results.get('poro2')
                mtr_k = results.get('kmod2')
                mtr_mi = results.get('gmod2')
                mtr_rho = results.get('dens2')
                #                kk = RP.VRHill (gr_k, gr_f, mtr_k)
                #                g = RP.VRHill (gr_mi, gr_f, mtr_mi)
                print('\ngrd', gr_k, gr_f, mtr_k, type(float(mtr_k)))
                rocktype = self.OM.new(
                    'rocktype',
                    fracgrain=gr_f,
                    fracmatrix=mtr_f,
                    grain=ngrain,
                    matrix=nmatrix,
                    k=10,
                    mi=20)  #vp=vp, vs=vs, rho = rho, k=k, mi=mi, poi=poi
                return rocktype

        except Exception as e:
            print('ERROR:', str(e))
        finally:
            UIM.remove(dlg.uid)

    @debugdecorator
    def DeleteRows(self, pos=0, numRows=1):
        if pos >= self.N_ROWS:
            i = pos - self.N_ROWS
            for j in range(numRows)[::-1]:
                self.OM.remove(self.rocktypemap.pop(i + j))

            self.GetView().BeginBatch()
            msg = wx.grid.GridTableMessage(
                self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, pos, numRows)
            self.GetView().ProcessTableMessage(msg)
            self.GetView().EndBatch()

            return True
        else:
            return False

    @debugdecorator
    def GetColLabelValue(self, col):
        if col == 0:
            return "Nome"
        elif col == 1:
            return "Cor"
        elif col == 2:
            return "Grain"
        elif col == 3:
            return "Matrix"
        else:
            return

    @debugdecorator
    def GetRowLabelValue(self, row):
        return str(row + 1)

    @debugdecorator
    def SetRowLabelValue(self, row, label):
        return

    @debugdecorator
    def GetNumberCols(self):
        return self.N_COLS


#        return len(self.propmap) + self.N_COLS

    @debugdecorator
    def GetNumberRows(self):
        return len(self.rocktypemap)

    @debugdecorator
    def GetAttr(self, row, col, kind):

        #if _iswxphoenix:
        attr = wx.grid.GridCellAttr().Clone()

        if col >= self.N_COLS:
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
        elif col == 0:
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
        elif col == 1:
            rocktype = self.OM.get(self.rocktypemap[row])
            attr.SetBackgroundColour(rocktype.color)
            attr.SetReadOnly(True)
        elif col == 2:
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
        elif col == 3:
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
        return attr

    @debugdecorator
    def GetValue(self, row, col):
        if col >= self.N_COLS:
            i = col - self.N_COLS
            prop = self.OM.get(self.propmap[i])
            value = prop.getdata(self.rocktypemap[row])
            if not np.isnan(value):
                return str(value)
            else:
                return ''
        elif col == 0:
            rocktype = self.OM.get(self.rocktypemap[row])
            return rocktype.name
        elif col == 1:
            return ''
        elif col == 2:
            rocktype = self.OM.get(self.rocktypemap[row])
            return rocktype.fracgrain + ' ' + rocktype.grain
        elif col == 3:
            rocktype = self.OM.get(self.rocktypemap[row])
            return rocktype.fracmatrix + ' ' + rocktype.matrix

    @debugdecorator
    def SetValue(self, row, col, value):
        if col >= self.N_COLS:
            i = col - self.N_COLS
            if value:
                value = float(value)
            else:
                value = np.nan
            prop = self.OM.get(self.propmap[i])
            prop.setdata(self.rocktypemap[row], value)
        elif col == 0:
            rocktype = self.OM.get(self.rocktypemap[row])
            rocktype.name = value
        elif col == 1:
            return
        elif col == 2:
            return
        elif col == 3:
            return

    @debugdecorator
    def set_color(self, row, color):
        rocktype = self.OM.get(self.rocktypemap[row])
        rocktype.color = color

    @debugdecorator
    def get_color(self, row):
        rocktype = self.OM.get(self.rocktypemap[row])
        return rocktype.color

    @debugdecorator
    def get_nameunit(self, col):
        if col >= self.N_COLS:
            i = col - self.N_COLS
            prop = self.OM.get(self.propmap[i])
            return prop.name, prop.unit

    @debugdecorator
    def set_nameunit(self, col, name, unit):
        if col >= self.N_COLS:
            i = col - self.N_COLS
            prop = self.OM.get(self.propmap[i])
            prop.name = name
            prop.unit = unit
Exemple #3
0
 def _delete_object_helper(self, *args, **kwargs):
     print('_delete_object_helper:', args[0])
     OM = ObjectManager()
     OM.remove(args[0])