//
//	SampleObjectSpecialGroups.cpp
//
//	Main entry point for VectorWorks Plug-in Object code.
//
//	Copyright © Nemetschek North America, Inc  2008.
//	All Rights Reserved.
//
//

#include "StdAfx.h"



#include "SampleObjectSpecialGroups.h"

/*
// Parametrics
														Message:					Result:
Action						Task							Gets						Returns
------------------------------------------------------------------------------------------------------------------------------
kParametricInitGlobals		Allocates global data				0								0 or kParametricSetupFailed
kParametricRecalculate		Regenerate objects					0								0
kParametricPreference		pose preference dialog				0 or parmFormat					0 or kParametricNotImplemented
kParametricDisposeGlobals	Disposes of global data				0								0
*/



long ParametricMain(long action, MCObjectHandle objHand, long message, long &userData)
//
//	Main entry point for parametric object regeneration external code resource.
//	See MiniCadHookIntf.h for constants.
//
{
	message; // Eliminate warning

	long	reply = kParametricNoErr;

	switch (action) {
		case kParametricInitGlobals : {
				/*
					This action is called when an overlay is activated and serves the
					primary purpose of allowing the external function to define any
					defaults and global information and to initialize data space that
					may be stored in userData.
				*/


				break;
			}



		case kParametricDisposeGlobals : {
				/*
					This action is called when an overlay is deactivated and serves the
					primary purpose of allowing the external function to dispose data
					space that may be stored in userData.
				*/


				break;
			}
		case kParametricRecalculate : {
			//
			//	This action is called to regenerate the look of a parametric object in response to a change
			//	in one of the parameter values on the object info palette, or a rotate, move, attribute change.
			//
			//	I would like to use a super class TParmRegen in this file and then have it overridden in specific
			//	files, but the userData scheme will not allow virtual functions. JAK
			//
			//	The message argument contains a handle to a wall, if we are inserted in a wall directly. Only for this action.
			//

			// -------------------------------------------------------
			// 2D representation
			gSDK->CreateArcN( WorldRect( -100, 100, 100, -100 ), 0, 180 );
			gSDK->CreateRectangle( WorldRect( -50, 50, 50, -50 ) );

			// -------------------------------------------------------
			// 3D representation
			MCObjectHandle	hExtrudeBase	= gSDK->CreatePolyshape();
			gSDK->AddVertex( hExtrudeBase, WorldPt(-100,-100), vtCorner, 0, false );
			gSDK->AddVertex( hExtrudeBase, WorldPt(0,-50), vtCorner, 0, false );
			gSDK->AddVertex( hExtrudeBase, WorldPt(100,-100), vtCorner, 0, false );
			gSDK->AddVertex( hExtrudeBase, WorldPt(100,100), vtCorner, 0, false );
			gSDK->AddVertex( hExtrudeBase, WorldPt(0,50), vtCorner, 0, false );
			gSDK->AddVertex( hExtrudeBase, WorldPt(-100,100), vtCorner, 0, false );
			gSDK->SetPolyShapeClose( hExtrudeBase, true );

			MCObjectHandle	hExtrude		= gSDK->CreateExtrude( 0, 20 );
			gSDK->AddObjectToContainer( hExtrudeBase, hExtrude );

			TransformMatrix	transfMat;
			::SetVectorRotationMatrix( Vector( 1, 0, 0 ), 90, transfMat );
			gSDK->SetEntityMatrix( hExtrude, transfMat );

			gSDK->CreateSphere( WorldPt3(0,0,0), 40 );

			// -------------------------------------------------------
			// prepare selection indication geometry
			MCObjectHandle	hSelGroup	= gSDK->CreateGroup();

			// 2D selectoin
			MCObjectHandle	h2DSel		= gSDK->CreateArcN( WorldRect( -100, 100, 100, -100 ), 0, 360 );
			gSDK->AddObjectToContainer( h2DSel, hSelGroup );

			MCObjectHandle	h3DSel1		= gSDK->DuplicateObject( hExtrude );
			gSDK->AddObjectToContainer( h3DSel1, hSelGroup );

			// set selection geometry for this object
			gSDK->SetCustomObjectSelectionGroup( objHand, hSelGroup );

			// -------------------------------------------------------
			// Custom wall opening
			MCObjectHandle	hOpExtrudeBase	= gSDK->CreatePolyshape();
			gSDK->AddVertex( hOpExtrudeBase, WorldPt(-100,-100), vtCorner, 0, false );
			gSDK->AddVertex( hOpExtrudeBase, WorldPt(0,-50), vtBezier, 0, false );
			gSDK->AddVertex( hOpExtrudeBase, WorldPt(100,-100), vtCorner, 0, false );
			gSDK->AddVertex( hOpExtrudeBase, WorldPt(100,100), vtCorner, 0, false );
			gSDK->AddVertex( hOpExtrudeBase, WorldPt(0,50), vtBezier, 0, false );
			gSDK->AddVertex( hOpExtrudeBase, WorldPt(-100,100), vtCorner, 0, false );
			gSDK->SetPolyShapeClose( hOpExtrudeBase, true );

			// create extrude for cutting the wall
			MCObjectHandle	hOpExtrude		= gSDK->CreateExtrude( -1000, 1000 );
			gSDK->AddObjectToContainer( hOpExtrudeBase, hOpExtrude );
			gSDK->SetEntityMatrix( hOpExtrude, transfMat );

			// set the cutting geometry
			gSDK->SetCustomObjectWallHoleGroup( objHand, hOpExtrude );
		}
	}

	return reply;
}
