ObjectBrowser to WpfTreeView conversion.
DenisFR
✭✭✭
Hello,
I want to make an addin which makes a new ProjectBrowser with filter ability.
Here the Code:
//Get ObjectBrowser Window
Window objectBrowserWin = UIEnvironment.Windows["ObjectBrowser"];
//Get Control normally as ABBInternal.ProjectBrowser.LayoutBrowser;
var layoutBrowser = objectBrowserWin.Control;
if ( !(layoutBrowser is null) && layoutBrowser.IsHandleCreated)
{
// Get first Control (Second is tool buttons)
System.Windows.Forms.Integration.ElementHost elementHost = (System.Windows.Forms.Integration.ElementHost)layoutBrowser.Controls[0];
WpfTreeView wpfTreeView = (WpfTreeView)elementHost.Child;
// Get TreeModel normally as ABBInternal.ProjectBrowser.LayoutTreeModel
TreeModel treeModel = wpfTreeView.TreeModel;
if (!(treeModel is null))
{
//Create new window
ToolWindow toolWindow = new ToolWindow("FilteredObjectBrowserWindow")
{
Caption = "Filtered ObjectBrowser."
};
UIEnvironment.Windows.AddDocked(toolWindow, System.Windows.Forms.DockStyle.Top, UIEnvironment.Windows["ObjectBrowser"] as ToolWindow);
WpfTreeView filterTreeView = new WpfTreeView();
// Create a copy treeModel
WpfTreeModel wpfTreeModel = new WpfTreeModel();
filterTreeView.TreeModel = wpfTreeModel;
wpfTreeModel.ExpandRootNodes = treeModel.ExpandRootNodes;
wpfTreeModel.ExpandedNodes.AddRange(treeModel.ExpandedNodes);
// Create the ElementHost control for hosting the
// WPF UserControl.
System.Windows.Forms.Integration.ElementHost host = new System.Windows.Forms.Integration.ElementHost
{
Dock = System.Windows.Forms.DockStyle.Fill,
// Assign the WPF UserControl to the ElementHost control's
// Child property.
Child = filterTreeView
};
// Add the ElementHost control to the form's
// collection of child controls.
toolWindow.Control.Controls.Add(host);
}
}
Window objectBrowserWin = UIEnvironment.Windows["ObjectBrowser"];
//Get Control normally as ABBInternal.ProjectBrowser.LayoutBrowser;
var layoutBrowser = objectBrowserWin.Control;
if ( !(layoutBrowser is null) && layoutBrowser.IsHandleCreated)
{
// Get first Control (Second is tool buttons)
System.Windows.Forms.Integration.ElementHost elementHost = (System.Windows.Forms.Integration.ElementHost)layoutBrowser.Controls[0];
WpfTreeView wpfTreeView = (WpfTreeView)elementHost.Child;
// Get TreeModel normally as ABBInternal.ProjectBrowser.LayoutTreeModel
TreeModel treeModel = wpfTreeView.TreeModel;
if (!(treeModel is null))
{
//Create new window
ToolWindow toolWindow = new ToolWindow("FilteredObjectBrowserWindow")
{
Caption = "Filtered ObjectBrowser."
};
UIEnvironment.Windows.AddDocked(toolWindow, System.Windows.Forms.DockStyle.Top, UIEnvironment.Windows["ObjectBrowser"] as ToolWindow);
WpfTreeView filterTreeView = new WpfTreeView();
// Create a copy treeModel
WpfTreeModel wpfTreeModel = new WpfTreeModel();
filterTreeView.TreeModel = wpfTreeModel;
wpfTreeModel.ExpandRootNodes = treeModel.ExpandRootNodes;
wpfTreeModel.ExpandedNodes.AddRange(treeModel.ExpandedNodes);
// Create the ElementHost control for hosting the
// WPF UserControl.
System.Windows.Forms.Integration.ElementHost host = new System.Windows.Forms.Integration.ElementHost
{
Dock = System.Windows.Forms.DockStyle.Fill,
// Assign the WPF UserControl to the ElementHost control's
// Child property.
Child = filterTreeView
};
// Add the ElementHost control to the form's
// collection of child controls.
toolWindow.Control.Controls.Add(host);
}
}
But this crash RS directly when I put mouse hover a node with that error:
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'ABB.Robotics.RobotStudio.Stations.Station' to type 'ABB.Robotics.RobotStudio.UI.WpfTreeNode'.
Source=ABB.Robotics.RobotStudio.UI
StackTrace:
at ABB.Robotics.RobotStudio.UI.WpfTreeModel.GetNodeToolTip(Object obj)
at ABB.Robotics.RobotStudio.UI.WpfTreeView.Grid_ToolTipOpening(Object sender, ToolTipEventArgs e)
at System.Windows.Controls.ToolTipEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent(Boolean fromKeyboard)
at System.Windows.Controls.PopupControlService.<>c__DisplayClass8_0.<InspectElementForToolTip>b__0(Object s, EventArgs e)
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ABBInternal.StudioAppFramework.StudioAppFrameworkHost.Run()
at RobotStudio.Program.Main(String[] args)
HResult=0x80004002
Message=Unable to cast object of type 'ABB.Robotics.RobotStudio.Stations.Station' to type 'ABB.Robotics.RobotStudio.UI.WpfTreeNode'.
Source=ABB.Robotics.RobotStudio.UI
StackTrace:
at ABB.Robotics.RobotStudio.UI.WpfTreeModel.GetNodeToolTip(Object obj)
at ABB.Robotics.RobotStudio.UI.WpfTreeView.Grid_ToolTipOpening(Object sender, ToolTipEventArgs e)
at System.Windows.Controls.ToolTipEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent(Boolean fromKeyboard)
at System.Windows.Controls.PopupControlService.<>c__DisplayClass8_0.<InspectElementForToolTip>b__0(Object s, EventArgs e)
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ABBInternal.StudioAppFramework.StudioAppFrameworkHost.Run()
at RobotStudio.Program.Main(String[] args)
How can I make what I want?
0
Comments
-
Up...
0 -
I'll try to remember to look into this issue when I get access to RS source code. I would need to run your addin against the source code to look for hick ups.—Maxim RiabichevPC Software Support Engineer0
Categories
- All Categories
- 5.5K RobotStudio
- 395 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings