def __init__(self, workGroup): """Constructor""" wx.Dialog.__init__(self, None, wx.ID_ANY, "Control Points"\ , size = (400,500)) self.workGroup = workGroup wk = self.workGroup patch = wk.inspector.currentPatch patchItem = wk.inspector.currentPatchItem geoItem = wk.inspector.tree.GetItemParent(patchItem) geo = wk.inspector.tree.GetItemData(geoItem) patch_id = geo.index(patch) patchInfo = geo.list_patchInfo[patch_id] patchInfo.showPoints = True # Refresh the viewer wk.Refresh() self.patch = patch self.patchInfo = patchInfo self._patchItem = patchItem self._geoItem = geoItem self._geo = geo from viewer import SelectedPoints self.selectedPoints = SelectedPoints(self.patch) pnl = wx.Panel(self) vbox = wx.BoxSizer(wx.VERTICAL) self.list_ctrl = wx.ListCtrl(pnl \ , style=wx.LC_REPORT|wx.EXPAND|wx.BORDER_SUNKEN) self.list_ctrl.InsertColumn(0, "Point") self.list_ctrl.InsertColumn(1, "x") self.list_ctrl.InsertColumn(2, "y") self.list_ctrl.InsertColumn(3, "z") self.list_ctrl.InsertColumn(4, "w") self.list_ctrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onItemSelected) rows = [] n = self.patch.shape # if 1D case if self.patch.dim == 1: for i in range(0,n[0]): P = self.patch.points[i,:] w = str(self.patch.weights[i]) ijk = "("+str(i)+")" Q = str(P[0]), str(P[1]), str(P[2]) rows.append(Point(ijk,Q,w)) # if 2D case if self.patch.dim == 2: for j in range(0,n[1]): for i in range(0,n[0]): P = self.patch.points[i,j,:] w = str(self.patch.weights[i,j]) ijk = "("+str(i)+","+str(j)+")" Q = str(P[0]), str(P[1]), str(P[2]) rows.append(Point(ijk,Q,w)) # if 3D case if self.patch.dim == 3: for k in range(0,n[2]): for j in range(0,n[1]): for i in range(0,n[0]): P = self.patch.points[i,j,k,:] w = str(self.patch.weights[i,j,k]) ijk = "("+str(i)+","+str(j)+","+str(k)+")" Q = str(P[0]), str(P[1]), str(P[2]) rows.append(Point(ijk,Q,w)) self.rows = rows index = 0 self.myRowDict = {} for row in self.rows: self.list_ctrl.InsertStringItem(index, row.ijk) self.list_ctrl.SetStringItem(index, 1, row.x) self.list_ctrl.SetStringItem(index, 2, row.y) self.list_ctrl.SetStringItem(index, 3, row.z) self.list_ctrl.SetStringItem(index, 4, row.w) self.myRowDict[index] = row index += 1 hbox = wx.BoxSizer(wx.VERTICAL) hbox.Add(self.list_ctrl, 1, wx.EXPAND, 5) pnl.SetSizer(hbox) vbox.Add(pnl, proportion=1, flag=wx.EXPAND, border=5) self.SetSizer(vbox) hbox2 = wx.BoxSizer(wx.HORIZONTAL) updateButton = wx.Button(self, label='Update') hbox2.Add(updateButton) vbox.Add(hbox2,flag=wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, border=10) self.list_ctrl.Bind(wx.EVT_RIGHT_DOWN, self.OnRightMouseClick) updateButton.Bind(wx.EVT_BUTTON, self.OnUpdate) self.menu_titles = ["Edit", "Mark", "Select"] self.menu_title_by_id = {} for title in self.menu_titles: self.menu_title_by_id[ wx.NewId() ] = title self.SetFocus() self.ID_CLOSE = wx.NewId() self.Bind(wx.EVT_MENU, self.OnClose, id=self.ID_CLOSE) accel_tbl = wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, self.ID_CLOSE )]) self.SetAcceleratorTable(accel_tbl)
class edtControlPoints(wx.Dialog): """""" #---------------------------------------------------------------------- def __init__(self, workGroup): """Constructor""" wx.Dialog.__init__(self, None, wx.ID_ANY, "Control Points"\ , size = (400,500)) self.workGroup = workGroup wk = self.workGroup patch = wk.inspector.currentPatch patchItem = wk.inspector.currentPatchItem geoItem = wk.inspector.tree.GetItemParent(patchItem) geo = wk.inspector.tree.GetItemData(geoItem) patch_id = geo.index(patch) patchInfo = geo.list_patchInfo[patch_id] patchInfo.showPoints = True # Refresh the viewer wk.Refresh() self.patch = patch self.patchInfo = patchInfo self._patchItem = patchItem self._geoItem = geoItem self._geo = geo from viewer import SelectedPoints self.selectedPoints = SelectedPoints(self.patch) pnl = wx.Panel(self) vbox = wx.BoxSizer(wx.VERTICAL) self.list_ctrl = wx.ListCtrl(pnl \ , style=wx.LC_REPORT|wx.EXPAND|wx.BORDER_SUNKEN) self.list_ctrl.InsertColumn(0, "Point") self.list_ctrl.InsertColumn(1, "x") self.list_ctrl.InsertColumn(2, "y") self.list_ctrl.InsertColumn(3, "z") self.list_ctrl.InsertColumn(4, "w") self.list_ctrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onItemSelected) rows = [] n = self.patch.shape # if 1D case if self.patch.dim == 1: for i in range(0,n[0]): P = self.patch.points[i,:] w = str(self.patch.weights[i]) ijk = "("+str(i)+")" Q = str(P[0]), str(P[1]), str(P[2]) rows.append(Point(ijk,Q,w)) # if 2D case if self.patch.dim == 2: for j in range(0,n[1]): for i in range(0,n[0]): P = self.patch.points[i,j,:] w = str(self.patch.weights[i,j]) ijk = "("+str(i)+","+str(j)+")" Q = str(P[0]), str(P[1]), str(P[2]) rows.append(Point(ijk,Q,w)) # if 3D case if self.patch.dim == 3: for k in range(0,n[2]): for j in range(0,n[1]): for i in range(0,n[0]): P = self.patch.points[i,j,k,:] w = str(self.patch.weights[i,j,k]) ijk = "("+str(i)+","+str(j)+","+str(k)+")" Q = str(P[0]), str(P[1]), str(P[2]) rows.append(Point(ijk,Q,w)) self.rows = rows index = 0 self.myRowDict = {} for row in self.rows: self.list_ctrl.InsertStringItem(index, row.ijk) self.list_ctrl.SetStringItem(index, 1, row.x) self.list_ctrl.SetStringItem(index, 2, row.y) self.list_ctrl.SetStringItem(index, 3, row.z) self.list_ctrl.SetStringItem(index, 4, row.w) self.myRowDict[index] = row index += 1 hbox = wx.BoxSizer(wx.VERTICAL) hbox.Add(self.list_ctrl, 1, wx.EXPAND, 5) pnl.SetSizer(hbox) vbox.Add(pnl, proportion=1, flag=wx.EXPAND, border=5) self.SetSizer(vbox) hbox2 = wx.BoxSizer(wx.HORIZONTAL) updateButton = wx.Button(self, label='Update') hbox2.Add(updateButton) vbox.Add(hbox2,flag=wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, border=10) self.list_ctrl.Bind(wx.EVT_RIGHT_DOWN, self.OnRightMouseClick) updateButton.Bind(wx.EVT_BUTTON, self.OnUpdate) self.menu_titles = ["Edit", "Mark", "Select"] self.menu_title_by_id = {} for title in self.menu_titles: self.menu_title_by_id[ wx.NewId() ] = title self.SetFocus() self.ID_CLOSE = wx.NewId() self.Bind(wx.EVT_MENU, self.OnClose, id=self.ID_CLOSE) accel_tbl = wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, self.ID_CLOSE )]) self.SetAcceleratorTable(accel_tbl) def OnClose(self, event): self.Close(True) def OnUpdate(self, event): wk = self.workGroup self.updatePatch() self.patchInfo.showPoints = False self.selectedPoints.clean() # Refresh the viewer wk.Refresh(inspector=True) def updatePatch(self): C = np.zeros_like(self.patch.control) n = self.patch.shape patch_old = self.patch.copy() for key, row in list(self.myRowDict.items()): x = float(row.x) y = float(row.y) z = float(row.z) w = float(row.w) ijk = row.ijk # remove '(' and ')' ijk = ijk[1:-1] # split with respect to ',' ijk = ijk.split(',') # convert to int ijk = [int(i) for i in ijk] # if 1D case if self.patch.dim == 1: i = ijk[0] C[i,:] = np.asarray([x,y,z,w]) # if 2D case if self.patch.dim == 2: i = ijk[0] ; j = ijk[1] C[i,j,:] = np.asarray([x,y,z,w]) # if 3D case if self.patch.dim == 3: i = ijk[0] ; j = ijk[1]; k = ijk[2] C[i,j,k,:] = np.asarray([x,y,z,w]) # TODO add set_weights in igakit.nurbs self.patch._array = C self.patch.set_points(C[...,:3]) # undo action wk = self.workGroup patch = self.patch patchItem = self._patchItem geo = self._geo geoItem = self._geoItem old = patch_old undo = UndoModifyPatch(wk, patchItem, patch, old, geo, geoItem) wk.appendAction(undo) def insertData(self): index = 0 for row in self.rows: self.list_ctrl.InsertStringItem(index, row.ijk) self.list_ctrl.SetStringItem(index, 1, row.x) self.list_ctrl.SetStringItem(index, 2, row.y) self.list_ctrl.SetStringItem(index, 3, row.z) self.list_ctrl.SetStringItem(index, 4, row.w) index += 1 def refreshList(self): self.list_ctrl.DeleteAllItems() self.insertData() def onItemSelected(self, event): wk = self.workGroup self.currentItem = event.m_itemIndex self.currentRow = self.myRowDict[self.currentItem] ijk = self.currentRow.ijk # remove '(' and ')' ijk = ijk[1:-1] # split with respect to ',' ijk = ijk.split(',') # convert to int ijk = [int(i) for i in ijk] if self.patch.dim == 1: list_ijk = [ijk[0]] if self.patch.dim == 2: list_ijk = [[ijk[0]], [ijk[1]]] if self.patch.dim == 3: list_ijk = [[ijk[0]], [ijk[1]], [ijk[2]]] self.selectedPoints.clean() self.selectedPoints.addPointsByIndices(list_ijk) wk.viewer.AddSelectedPoints(self.selectedPoints) # Refresh the viewer wk.Refresh() def editPoint(self): wk = self.workGroup x = float(self.currentRow.x) y = float(self.currentRow.y) z = float(self.currentRow.z) w = float(self.currentRow.w) dlg = edtCoordinatesTxtDialog(None, title="Edit Point", x=x,y=y,z=z,w=w) dlg.ShowModal() xtxt, ytxt, ztxt, wtxt = dlg.getValue() try: xcenter, ycenter, zcenter = wk.viewer.lookAt.GetCenter() if xtxt is not None: x = float(xtxt) else: x = xcenter if ytxt is not None: y = float(ytxt) else: y = ycenter if ztxt is not None: z = float(ztxt) else: z = zcenter if wtxt is not None: w = float(wtxt) else: w = 1.0 self.currentRow.x = str(x) self.currentRow.y = str(y) self.currentRow.z = str(z) self.currentRow.w = str(w) except: pass dlg.Destroy() def toSelectedPoint(self): wk = self.workGroup x = float(self.currentRow.x) y = float(self.currentRow.y) z = float(self.currentRow.z) w = float(self.currentRow.w) P = [x,y,z,w] # self.selectedPoints.addPointsByIndices(list_ijk) # wk.viewer.AddSelectedPoints(self.selectedPoints) # # ijk = self.currentRow.ijk # # selectedPoints = SelectedPoints(self.patch) # X,Y,Z = pointsToList(self.patch.points) # list_ind = findIndex(X,Y,xmin,xmax,ymin,ymax) # list_ijk = fromIndexToCoord(patch, list_ind) # selectedPoints.addPointsByIndices(list_ijk) # self.AddSelectedPoints(selectedPoints) # # wk.viewer.AddSelectedPoints(P) # wk.Refresh() def toMarkerPoint(self): wk = self.workGroup x = float(self.currentRow.x) y = float(self.currentRow.y) z = float(self.currentRow.z) w = float(self.currentRow.w) P = [x,y,z,w] wk.viewer.AddMarkerPoint(P) wk.Refresh() def OnRightMouseClick(self, event): ### 2. Launcher creates wxMenu. ### menu = wx.Menu() for (id,title) in list(self.menu_title_by_id.items()): ### 3. Launcher packs menu with Append. ### toAppend = True title_id = menu.Append( id, title ) ### 4. Launcher registers menu handlers with EVT_MENU, on the menu. ### menu.Bind( wx.EVT_MENU, self.MenuSelectionCb, title_id ) ### 5. Launcher displays menu with call to PopupMenu, invoked on the source component, passing event's GetPoint. ### self.PopupMenu( menu) menu.Destroy() # destroy to avoid mem leak def MenuSelectionCb( self, event ): # do something operation = self.menu_title_by_id[ event.GetId() ] if operation == "Edit": self.editPoint() self.refreshList() if operation == "Select": self.toSelectedPoint() self.refreshList() if operation == "Mark": self.toMarkerPoint() self.refreshList()