//================================================================
// Create a vector (represented by a linear Spline)
//
// Plugin for EQUINOX-3D
//
// AUTHOR:  Gabor Nagy
// DATE:    2025-Apr-08 19:46:07
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================
#include <math.h>
#include <stdio.h>


#include <EMalloc.h>
#include <EPlugins.h>

#include <Xe/Label.h>
#include <Xe/Matrix.h>
#include <Xe/Scale.h>
#include <Xe/ToggleButton.h>

#include <E3D/UI/CreateMacros.h>
#include <E3D/UI/Panel.h>
#include <E3D/UI/Panels.h>



extern EpCImage  Image_VectorBig;

static EPlugin*  _Plugin = NULL;


typedef struct
{
	XeWidget  ArrowOnW,
	          ModeP1P2W, ModeP1DirW,
	          VX0ScaleW, VY0ScaleW, VZ0ScaleW, VX1ScaleW, VY1ScaleW, VZ1ScaleW, LengthW;
} E3dResourcesGUI;

static XeDWidget		_MenuButton = NULL;


static E3dObjectComponentClass*  _ComponentClass = NULL;

//========================================
// Update() (create/change) method
//========================================
static E3dObject* _Update1(E3dObject* PObject, E3dObjectComponent* PComponentTemplate,  EUpdateFlags* PTriggeredUpdateFlags, EChangeFlags* PTriggeredSceneChangeFlags,  const EBool PCheckOnly)
{
	if(PCheckOnly) return(NULL);

	E3dSpline*      LSpline;
	E3dVectorInfo*  LInfo;

	if(PObject == NULL)
	{
		E_New(E3dSpline, LSpline);
		PObject = (E3dObject*)LSpline;

		LInfo = (E3dVectorInfo*)E3dObjectComponent_Add((E3dObject*)LSpline, _ComponentClass);
		if(PComponentTemplate && PComponentTemplate->Class == _ComponentClass) _ComponentClass->Copy(NULL, PComponentTemplate, NULL, (E3dObjectComponent*)LInfo);
	}
	else
	{
		if(!EObject_IsSubClass(PObject, E3dSpline)) return(NULL);

		LSpline = (E3dSpline*)PObject;
		LInfo = (E3dVectorInfo*)E3dObjectComponent_ByClass((E3dObject*)LSpline, _ComponentClass, FALSE);
		if(!PCheckOnly && LInfo->AttributeChangeCount == 0 && LInfo->InputChangeCount == 0) return(NULL);    // If no attributes or inputs changed, bail
	}

	{
		E3dSplineCV*  LCV;
		EIndex        LNV;

		if(LInfo->ArrowOn) LNV = 10;
		else LNV = 2;

		if(LSpline->CVs.Count != LNV)
		{
			E3dSpline_FreeCVs(LSpline);
			LSpline->CVs.Items = E3dSplineCVs_New(E3dSplineLINEAR, LNV);LSpline->CVs.Count = LSpline->CVs.CountAllocated = LNV;
		}

		LCV = LSpline->CVs.Items;
		LCV->Position = LInfo->P0;LCV++;

		if(LInfo->ArrowOn) E3d_CreateVectorArrow(LSpline->CVs.Items,  LInfo->P1.X, LInfo->P1.Y, LInfo->P1.Z);
		else
		{
			LCV->Position = LInfo->P1;
		}
		E3dSpline_CreateLinearSegments(LSpline);

		LInfo->AttributeChangeCount = LInfo->InputChangeCount = 0;
	}

	return(PObject);
}


static void _DCB_Values(XeWidget PW, EPointer PClientData, EPointer PCallData)
{
	E3dScene*                LScene = E3d_Scene;
	E3dObjectPanel*          LPanel = (E3dObjectPanel*)PClientData;
	E3dObject*               LObject = LPanel->Object;
	E3dVectorInfo*           LInfo = (E3dVectorInfo*)E3dObjectComponent_ByClass(LObject, _ComponentClass, FALSE);
	EChangeFlags             LChanged = E3dObject_GetChangeFlagsByClass(LObject);
	XeComponentClassDrawer*  LDrawer = XeInfoPanel_GetFolderByClass((XeInfoPanel*)LPanel, _ComponentClass);
	E3dResourcesGUI*         LGUI = (E3dResourcesGUI*)(LDrawer->ResourcesGUI);

	LInfo->P0.X = XeScale_GetValue_Coord(LGUI->VX0ScaleW);
	LInfo->P0.Y = XeScale_GetValue_Coord(LGUI->VY0ScaleW);
	LInfo->P0.Z = XeScale_GetValue_Coord(LGUI->VZ0ScaleW);

	switch(LInfo->CoordinateMode)
	{
		case E3dVTM_P1_P2:
			LInfo->P1.X = XeScale_GetValue_Coord(LGUI->VX1ScaleW);
			LInfo->P1.Y = XeScale_GetValue_Coord(LGUI->VY1ScaleW);
			LInfo->P1.Z = XeScale_GetValue_Coord(LGUI->VZ1ScaleW);
		break;

		case E3dVTM_P1_DIR:
			LInfo->P1.X = XeScale_GetValue_Coord(LGUI->VX1ScaleW) + LInfo->P0.X;
			LInfo->P1.Y = XeScale_GetValue_Coord(LGUI->VY1ScaleW) + LInfo->P0.Y;
			LInfo->P1.Z = XeScale_GetValue_Coord(LGUI->VZ1ScaleW) + LInfo->P0.Z;
		break;
	}

	const E3dCoord3  LP0ToP1 = E3dCoord3_s(LInfo->P1.X - LInfo->P0.X,  LInfo->P1.Y - LInfo->P0.Y, LInfo->P1.Z - LInfo->P0.Z);
	E3dCoordinate    LLength;E3d_Length3_v(LP0ToP1, LLength);

	XeScale_SetValue_Coord(LGUI->LengthW, LLength, FALSE);

	LInfo->AttributeChangeCount++;
	E3dObject_CustomUpdate(LObject, LInfo,  E3dCallALL,  &LChanged);
	E3dWindows_RedrawByChangeFlags(LScene, LChanged);
}


static void _DCB(XeWidget PW, EPointer PClientData, EPointer PCallData)
{
	E3dScene*                LScene = E3d_Scene;
	E3dObjectPanel*          LPanel = (E3dObjectPanel*)PClientData;
	E3dObject*               LObject = LPanel->Object;
	E3dVectorInfo*           LInfo = (E3dVectorInfo*)E3dObjectComponent_ByClass(LObject, _ComponentClass, FALSE);
	EChangeFlags             LChanged = 0;
	XeComponentClassDrawer*  LDrawer = XeInfoPanel_GetFolderByClass((XeInfoPanel*)LPanel, _ComponentClass);
	E3dResourcesGUI*         LGUI = (E3dResourcesGUI*)(LDrawer->ResourcesGUI);

	if(PW == LGUI->ArrowOnW)
	{
		LInfo->ArrowOn = ((XeToggleButtonCallbackStruct*)PCallData)->Set;

		LChanged |= E3dObject_GetChangeFlagsByClass(LObject);
		LInfo->AttributeChangeCount++;
		E3dObject_CustomUpdate(LObject, LInfo,  E3dCallALL,  &LChanged);
	}
	else if(PW == LGUI->LengthW)
	{
		E3dCoord3            LP0ToP1 = E3dCoord3_s(LInfo->P1.X - LInfo->P0.X,  LInfo->P1.Y - LInfo->P0.Y, LInfo->P1.Z - LInfo->P0.Z);
		const E3dCoordinate  LLength = XeScale_GetValue_Coord(LGUI->LengthW);

		E3d_Normalize3_v(LP0ToP1);
		LInfo->P1.X = LInfo->P0.X + LP0ToP1.X * LLength;
		LInfo->P1.Y = LInfo->P0.Y + LP0ToP1.Y * LLength;
		LInfo->P1.Z = LInfo->P0.Z + LP0ToP1.Z * LLength;

		switch(LInfo->CoordinateMode)
		{
			case E3dVTM_P1_P2:
				XeScale_SetValue_Coord(LGUI->VX1ScaleW, LInfo->P1.X, FALSE);
				XeScale_SetValue_Coord(LGUI->VY1ScaleW, LInfo->P1.Y, FALSE);
				XeScale_SetValue_Coord(LGUI->VZ1ScaleW, LInfo->P1.Z, FALSE);
			break;

			case E3dVTM_P1_DIR:
				XeScale_SetValue_Coord(LGUI->VX1ScaleW, LInfo->P1.X - LInfo->P0.X, FALSE);
				XeScale_SetValue_Coord(LGUI->VY1ScaleW, LInfo->P1.Y - LInfo->P0.Y, FALSE);
				XeScale_SetValue_Coord(LGUI->VZ1ScaleW, LInfo->P1.Z - LInfo->P0.Z, FALSE);
			break;
		}

		LChanged |= E3dObject_GetChangeFlagsByClass(LObject);
		LInfo->AttributeChangeCount++;
		E3dObject_CustomUpdate(LObject, LInfo,  E3dCallALL,  &LChanged);
	}
	else if(PW == LGUI->ModeP1P2W)
	{
		if(((XeToggleButtonCallbackStruct*)PCallData)->Set)
		{
			LInfo->CoordinateMode = E3dVTM_P1_P2;

			LInfo->P1.X = XeScale_GetValue_Coord(LGUI->VX1ScaleW);
			LInfo->P1.Y = XeScale_GetValue_Coord(LGUI->VY1ScaleW);
			LInfo->P1.Z = XeScale_GetValue_Coord(LGUI->VZ1ScaleW);

			LChanged |= E3dObject_GetChangeFlagsByClass(LObject);
			LInfo->AttributeChangeCount++;
			E3dObject_CustomUpdate(LObject, LInfo,  E3dCallALL,  &LChanged);
		}
	}
	else if(PW == LGUI->ModeP1DirW)
	{
		if(((XeToggleButtonCallbackStruct*)PCallData)->Set)
		{
			LInfo->CoordinateMode = E3dVTM_P1_P2;

			LInfo->P1.X = XeScale_GetValue_Coord(LGUI->VX1ScaleW);
			LInfo->P1.Y = XeScale_GetValue_Coord(LGUI->VY1ScaleW);
			LInfo->P1.Z = XeScale_GetValue_Coord(LGUI->VZ1ScaleW);

			LChanged |= E3dObject_GetChangeFlagsByClass(LObject);
			LInfo->AttributeChangeCount++;
			E3dObject_CustomUpdate(LObject, LInfo,  E3dCallALL,  &LChanged);
		}
	}

	E3dWindows_RedrawByChangeFlags(LScene, LChanged);
}


static void _UpdateDialog(E3dVectorInfo* PInfo, E3dResourcesGUI* PResourcesGUI)
{
	XeToggleButton_SetState(PResourcesGUI->ArrowOnW, PInfo->ArrowOn, FALSE);

	XeScale_SetValue_Coord(PResourcesGUI->VX0ScaleW, PInfo->P0.X, FALSE);
	XeScale_SetValue_Coord(PResourcesGUI->VY0ScaleW, PInfo->P0.Y, FALSE);
	XeScale_SetValue_Coord(PResourcesGUI->VZ0ScaleW, PInfo->P0.Z, FALSE);

	switch(PInfo->CoordinateMode)
	{
		case E3dVTM_P1_P2:
			XeToggleButton_SetState(PResourcesGUI->ModeP1P2W, TRUE, FALSE);
			XeToggleButton_SetState(PResourcesGUI->ModeP1DirW, FALSE, FALSE);

			XeScale_SetValue_Coord(PResourcesGUI->VX1ScaleW, PInfo->P1.X, FALSE);
			XeScale_SetValue_Coord(PResourcesGUI->VY1ScaleW, PInfo->P1.Y, FALSE);
			XeScale_SetValue_Coord(PResourcesGUI->VZ1ScaleW, PInfo->P1.Z, FALSE);

			XeScale_SetValue_Coord(PResourcesGUI->LengthW, PInfo->P1.Z, FALSE);
		break;

		case E3dVTM_P1_DIR:
			XeToggleButton_SetState(PResourcesGUI->ModeP1P2W, FALSE, FALSE);
			XeToggleButton_SetState(PResourcesGUI->ModeP1DirW, TRUE, FALSE);

			XeScale_SetValue_Coord(PResourcesGUI->VX1ScaleW, PInfo->P1.X - PInfo->P0.X, FALSE);
			XeScale_SetValue_Coord(PResourcesGUI->VY1ScaleW, PInfo->P1.Y - PInfo->P0.Y, FALSE);
			XeScale_SetValue_Coord(PResourcesGUI->VZ1ScaleW, PInfo->P1.Z - PInfo->P0.Z, FALSE);
		break;
	}

	const E3dCoord3  LP0ToP1 = E3dCoord3_s(PInfo->P1.X - PInfo->P0.X,  PInfo->P1.Y - PInfo->P0.Y, PInfo->P1.Z - PInfo->P0.Z);
	E3dCoordinate    LLength;E3d_Length3_v(LP0ToP1, LLength);

	XeScale_SetValue_Coord(PResourcesGUI->LengthW, LLength, FALSE);
}


//========================================
// GUI
//========================================
static void _GUI(E3dObject* PObject, E3dObjectComponent* PInfo, void* PPanel, void* PDrawer, const int PAction)
{
	E3dObjectPanel*          LPanel = (E3dObjectPanel*)PPanel;
	XeComponentClassDrawer*  LDrawer = (XeComponentClassDrawer*)PDrawer;
	E3dVectorInfo*           LInfo = (E3dVectorInfo*)PInfo;

	switch(PAction)
	{
		case E_UPDATE:
			if(LDrawer->ResourcesGUI)
			{
				E3dResourcesGUI*  LGUI = (E3dResourcesGUI*)(LDrawer->ResourcesGUI);

				_UpdateDialog(LInfo, LGUI);
			}
			else
			{
				XeWidget  LTopMatrixW = LDrawer->Drawer.DrawerW, LMatrixW, LTypeMatrixW, LW;
				XeWidget  LIndentWs[7];int  LIndentN;      // For indenting the Scale Widgets
				XeWidget  LTraverseWs[7];int  LTraverseN;  // For TextField traversal
				EArg      Args[256];int  ArgCnt;

				E3dResourcesGUI*  LGUI;ENew(LGUI);LDrawer->ResourcesGUI = LGUI;

				EXeStart;
				EXeSetArg(XeNShadowThickness, 0);
				EXeSetArg(XeNHighlightThickness, 0);
				EXeSetArg(XeNFontList, Xe_LabelFontList);
				EXeSetArg(XeNSet, LInfo->ArrowOn);
				LGUI->ArrowOnW = LW = XeWidget_ManagedNew("Arrow", XeToggleButton_class, LTopMatrixW, Args, ArgCnt);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNMarginTop, 5);
				EXeSetArg(XeNRadioBehavior, TRUE);
				EXeSetArg(XeNOrientation, XeHORIZONTAL);
				EXeSetArg(XeNSpacingX, 6);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
				EXeSetArg(XeNResizableX, FALSE);EXeSetArg(XeNAlignmentX, XeAlignBEGINNING);
				LTypeMatrixW = XeWidget_ManagedNew("", XeMatrixWidget_class, LTopMatrixW, Args, ArgCnt);

				EXeStart;
				EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
				EXeSetArg(XeNForegroundColorPtr, &Xe_ForegroundRGBAiColor);
				EXeSetArg(XeNFontList, Xe_LabelFontList);
				EXeSetArg(XeNResizableX, FALSE);EXeSetArg(XeNAlignmentX, XeAlignBEGINNING);
				XeWidget_ManagedNew("Type:", XeLabelWidget_class, LTypeMatrixW, Args, ArgCnt);

				EXeStart;
				EXeSetArg(XeNShadowThickness, 0);
				EXeSetArg(XeNHighlightThickness, 0);
				EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
				EXeSetArg(XeNForegroundColorPtr, &Xe_ForegroundRGBAiColor);
				EXeSetArg(XeNSelectColorPtr, &Xe_HighlightRGBAiColor);
				EXeSetArg(XeNFontList, Xe_LabelFontList);
				EXeSetArg(XeNSet, (EBool)(LInfo->CoordinateMode == E3dVTM_P1_P2));
				LGUI->ModeP1P2W = LW = XeWidget_ManagedNew("P1-P2", XeToggleButton_class, LTypeMatrixW, Args, ArgCnt);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNShadowThickness, 0);
				EXeSetArg(XeNHighlightThickness, 0);
				EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
				EXeSetArg(XeNForegroundColorPtr, &Xe_ForegroundRGBAiColor);
				EXeSetArg(XeNSelectColorPtr, &Xe_HighlightRGBAiColor);
				EXeSetArg(XeNFontList, Xe_LabelFontList);
				EXeSetArg(XeNSet, (EBool)(LInfo->CoordinateMode == E3dVTM_P1_DIR));
				LGUI->ModeP1DirW = LW = XeWidget_ManagedNew("P1 & direction", XeToggleButton_class, LTypeMatrixW, Args, ArgCnt);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNMarginSizeX, 2);EXeSetArg(XeNMarginSizeY, 2);
				EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
				EXeSetArg(XeNOrientation, XeHORIZONTAL);
				EXeSetArg(XeNColumns, 3);
				EXeSetArg(XeNSpacingX, 2);
				EXeSetArg(XeNResizableX, FALSE);EXeSetArg(XeNAlignmentX, XeAlignBEGINNING);
				LMatrixW = XeWidget_ManagedNew("MatrixW", XeMatrixWidget_class, LTopMatrixW, Args, ArgCnt);

				LTraverseN = 0;
				LIndentN = 0;
				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LIndentWs[LIndentN++] = LGUI->VX0ScaleW = LW = XeScale_New_Coord(LMatrixW, "XYZ:", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB_Values, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LGUI->VY0ScaleW = LW = XeScale_New_Coord(LMatrixW, "", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB_Values, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LGUI->VZ0ScaleW = LW = XeScale_New_Coord(LMatrixW, "", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB_Values, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LIndentWs[LIndentN++] = LGUI->VX1ScaleW = LW = XeScale_New_Coord(LMatrixW, "XYZ:", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB_Values, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LGUI->VY1ScaleW = LW = XeScale_New_Coord(LMatrixW, "", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB_Values, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LGUI->VZ1ScaleW = LW = XeScale_New_Coord(LMatrixW, "", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB_Values, (EPointer)LPanel);

				EXeStart;
				EXeSetArg(XeNTextFieldDigits, 9);EXeSetArg(XeNDecimalPoints, 5);
				EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
				EXeSetArg(XeNCreateScale, FALSE);
				LTraverseWs[LTraverseN++] = LIndentWs[LIndentN++] = LGUI->LengthW = LW = XeScale_New_Coord(LTopMatrixW, "Length", Args, ArgCnt);
				XeScale_SetValueAndRanges_Coord(LW,  0.0,  -1000000.0,  1000000,  -10.0, 10,  FALSE);
				XeAddCallback(LW, XeNValueChangedCallback, _DCB, (EPointer)LPanel);

				XeWidgets_IndentFromLeft(LIndentWs, LIndentN, 0);

				_UpdateDialog(LInfo, LGUI);

// Set up TextField traversal
//
				XeTraversal_SetRing(LTraverseWs, LTraverseN);
			}
		break;
	}
}


//========================================
// Menu callback
//========================================
static void _MCB(XeWidget PW, EPointer PClientData, EPointer PCallData)
{
	E3dTpl_ObjectComponentActivateCB_Geometry(_ComponentClass);
}


//========================================
// Entry point of the plugin
//========================================
int E_PluginInit(EPlugin* PPlugin)
{
	_Plugin = PPlugin;

	{
		_ComponentClass = E3d_VectorObjectComponentClass;
		_ComponentClass->Update1 = _Update1;
		_ComponentClass->GUI = _GUI;
	}

	_MenuButton = XePushButton_Add(Xe_App, "Menu->Create", "Vector", '\0', NULL, NULL, TRUE, NULL, _MCB, (EPointer)0);

	return(E_SUCCESS);
}


//========================================
// Exit method of the plugin
//========================================
int E_PluginExit(const EBool PExiting)
{
	if(!PExiting || Xe_GUIFreeOnExit) XeItemFree(_MenuButton);

// Check if ObjectComponentClasses have been already removed
//
	if(E3dObjectComponent_Classes.Count > 0)
	{
		_ComponentClass->Update1 = NULL;
		_ComponentClass->GUI = NULL;
	}

	return(E_SUCCESS);
}
