Untitled
unknown
plain_text
a year ago
12 kB
5
Indexable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Size = System.Drawing.Size;
using static PhotoPlugin.AcadStaticHelper;
using static PhotoPlugin.PaletteControlHelper;
using static PhotoPlugin.MessageBoxHelper;
using static PhotoPlugin.ActivationStaticHelper;
using static PhotoPlugin.SysConStaticHelper;
using Exception = System.Exception;
#if BricsCad_Compiler
using Bricscad.ApplicationServices;
using Cad = Bricscad.ApplicationServices.Application;
using Teigha.DatabaseServices;
using Bricscad.EditorInput;
using Bricscad.Windows;
using Teigha.Runtime;
#elif AutoCad_Compiler
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Cad = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
#endif
namespace PhotoPlugin
{
#region Class
public static class PaletteStarter
{
#region Properties
public static PaletteSet _palette;
private static bool _isVisible;
#endregion
#region Methods
[CommandMethod("PhotoPluginClose", CommandFlags.Session)]
public static void ClosePalette()
{
try
{
if (_palette != null)
{
_palette.Close();
_palette = null;
}
}
catch
{
}
}
[CommandMethod("PhotoPlugin",CommandFlags.Session)]
public static void LoadPalette()
{
try
{
SetIsNotPlan2();
SetStaticAcadHelper();
if (AcadStatic != null)
{
AcadStatic.CurrentDoc.SendStringToExecute("PlotPluginClose\n", false, false, true);
AcadStatic.CurrentDoc.SendStringToExecute("Plan2ExtClosePalettes\n", false, false, true);
AcadStatic.CurrentDoc.SendStringToExecute("Plan2PointCloudClosePalettes\n", false, false, true);
}
Debug.WriteLine("Start to check loaded palette status ...");
if (_palette != null)
Debug.WriteLine("Palette is still created ...");
if (_palette == null)
{
Debug.WriteLine("No palette is created ...");
Debug.WriteLine("Start to create new auto cad palette ...");
_palette = new PaletteSet(
"PhotoPlugin",
"PhotoPlugin",
new Guid("{1836C7AC-C70E-4CF7-AA05-F6298D257046}"));
SetDisplayProperties();
LoginUserId = UserId_PlanQuadratBestandsaufnahmenGmbH;
SetInterfacesPhotoPlugin();
SetDefaultIcon();
var documentCollection = Cad.DocumentManager;
documentCollection.DocumentBecameCurrent += (s, e) =>
_palette.Visible = e.Document != null && _isVisible;
documentCollection.DocumentCreated += (s, e) =>
_palette.Visible = _isVisible;
documentCollection.DocumentToBeDeactivated += (s, e) =>
_isVisible = _palette.Visible;
documentCollection.DocumentToBeDestroyed += (s, e) =>
{
_isVisible = _palette.Visible;
if (documentCollection.Count == 1)
_palette.Visible = false;
};
Debug.WriteLine("Finished to create new auto cad palette ...");
}
SetDockingProperties();
AcadStatic.DocManager.DocumentActivated += DocumentChanged_Event;
void DocumentChanged_Event(object sender, DocumentCollectionEventArgs e)
{
SetStaticAcadHelper();
}
void SetDockingProperties()
{
Debug.WriteLine("Start to set palette docking properties ...");
_palette.Dock = DockSides.Left;
_palette.RolledUp = false;
_palette.Visible = true;
Debug.WriteLine("Docking properties are set ...");
}
void SetDisplayProperties()
{
Debug.WriteLine("Start to set palette display properties ...");
_palette.Size = new Size(500, 700);
_palette.MinimumSize = new Size(500, 700);
_palette.Style = PaletteSetStyles.ShowAutoHideButton |
PaletteSetStyles.ShowCloseButton |
PaletteSetStyles.ShowPropertiesMenu;
Debug.WriteLine("Display properties are set ...");
}
void SetDefaultIcon()
{
Debug.WriteLine("Start to set icon for palette ...");
var paletteImage = new PaletteImageHelper();
var icon = paletteImage.GetIconPalette();
if (icon == null)
{
Debug.WriteLine("No icon set ...");
}
if (icon != null)
{
_palette.SetIcon(icon);
Debug.WriteLine("Icon set ...");
}
}
void SetInterfacesPhotoPlugin()
{
try
{
Debug.WriteLine("Start to set photo palette main ...");
var photoPaletteMain = new PhotoPaletteMain(_palette);
PhotoPaletteMainInterface = photoPaletteMain;
_palette.AddVisual("Fotodoku", photoPaletteMain);
Debug.WriteLine("Finished to set photo palette main ...");
}
catch (Exception error)
{
Debug.WriteLine("Error to set photo palette main ...");
Debug.WriteLine(error.Message);
}
}
}
catch (Exception error)
{
ShowMessageBoxError("Fehler beim laden der Palette ...", error);
}
}
static string SetIsNotPlan2()
{
string isPlan2FilePath = null;
Debug.WriteLine("Start to get IsNotPlan2 from dll path file ...");
try
{
var dllHelper = new DllHelper();
var fullDllPath = dllHelper.GetLoadedDllFileInfo();
if (fullDllPath == null || fullDllPath.Directory == null)
isPlan2FilePath = null;
if (fullDllPath != null || fullDllPath.Directory != null)
isPlan2FilePath = fullDllPath.Directory + @"\config\IsNotPlan2.conf";
IsNotPlan2= File.Exists(isPlan2FilePath);
Debug.WriteLine("Finished to get IsNotPlan2 from dll path file ...");
}
catch (Exception error)
{
Debug.WriteLine("Error to get IsNotPlan2 from dll path file ...");
Debug.WriteLine(error.Message);
}
return isPlan2FilePath;
}
[CommandMethod("FindCmdDuplicates")]
public static void FindCmdDuplicatesCmd()
{
string asmPath = SelectAssembly();
if (asmPath == null)
return;
FindCmdDuplicates(asmPath);
}
private static string SelectAssembly()
{
System.Windows.Forms.OpenFileDialog dlg =
new System.Windows.Forms.OpenFileDialog();
dlg.Title = "Load Assembly File";
dlg.InitialDirectory = Environment.GetFolderPath(
Environment.SpecialFolder.Desktop);
dlg.Filter = ".Net Assembly (*.dll)|*.dll";
dlg.FilterIndex = 1;
dlg.RestoreDirectory = true;
while (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
try
{
AssemblyName asmName =
AssemblyName.GetAssemblyName(dlg.FileName);
return dlg.FileName;
}
catch (BadImageFormatException )
{
System.Windows.Forms.MessageBox.Show(
"Sorry the file is not a valid .Net assembly...",
"Invalid Assembly",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
}
}
return null;
}
public static void FindCmdDuplicates(string asmPath)
{
Dictionary<string, List<MethodInfo>> map =
new Dictionary<string, List<MethodInfo>>();
Assembly asm = Assembly.LoadFile(asmPath);
Type[] expTypes = asm.GetTypes();
foreach (Type type in expTypes)
{
MethodInfo[] methods = type.GetMethods();
foreach (MethodInfo method in methods)
{
CommandMethodAttribute attribute =
GetCommandMethodAttribute(method);
if (attribute == null)
continue;
if (!map.ContainsKey(attribute.GlobalName))
{
var methodInfo = new List<MethodInfo>();
map.Add(attribute.GlobalName, methodInfo);
}
map[attribute.GlobalName].Add(method);
}
}
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
foreach (var keyValuePair in map)
{
if (keyValuePair.Value.Count > 1)
{
ed.WriteMessage(
"\nDuplicate Attribute: " + keyValuePair.Key);
foreach (var method in keyValuePair.Value)
{
ed.WriteMessage(
"\n – Method: " + method.Name);
}
}
}
}
public static CommandMethodAttribute GetCommandMethodAttribute(
MethodInfo method)
{
object[] attributes = method.GetCustomAttributes(true);
foreach (object attribute in attributes)
{
if (attribute is CommandMethodAttribute)
{
return attribute as CommandMethodAttribute;
}
}
return null;
}
#endregion
}
#endregion
}Editor is loading...
Leave a Comment