I have some “big algorithm” in C++ with many .cpp files and also header files and I am actually supposed to do my homework, which I honestly can’t get it done at the moment. That’s why, I appreciate any tipps and help to get started.
So here comes the one of the many .cpp files:
/////////////////////////////////////////////////////////////////////////////
// cmdCiEBBox,cpp
//
#include "stdafx.h"
#include "LinAlg_Global.h"
#include "LinAlg_Matrix.h"
#include "LinAlg_Vector.h"
#include "LinAlg_MatrixOp.h"
#include "LinAlg_VectorOp.h"
#include "TGFRhinoPluginGlobal.h"
#include "TGFRhinoPlugin_BBox.h"
#include "TGFRhinoPlugin_ALLBBox.h"
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN cmdCiEBBox command
//
class CCommandCiEBBox : public CRhinoCommand
{
public:
CCommandCiEBBox() {}
~CCommandCiEBBox() {}
UUID CommandUUID()
{
// {94E40A57-10C2-4606-872B-D469DE6D0B1A}
static const GUID OrientedBBoxCommand_UUID =
{ 0x94E40A57, 0x10C2, 0x4606, { 0x87, 0x2B, 0xD4, 0x39, 0xDE, 0x6D, 0x0B, 0x1A } };
return OrientedBBoxCommand_UUID;
}
const wchar_t* EnglishCommandName() { return L"CiEBBox"; }
const wchar_t* LocalCommandName() { return L"CiEBBox"; }
CRhinoCommand::result RunCommand( const CRhinoCommandContext& );
};
static class CCommandCiEBBox theCiEBBoxCommand;
CRhinoCommand::result CCommandCiEBBox::RunCommand( const CRhinoCommandContext& context )
{
// get type of desired bbox (oriented or axis aligned)
// http://wiki.mcneel.com/developer/sdksamples/commandlineoptions
// http://wiki.mcneel.com/developer/sdksamples/setactiveview
// *** Get options for BBox generation ***
BBoxType desBBoxType = ALL_BBOX;
double BBoxEps = 0.001;
CiEPlg_BBox* pCiEBBOX = 0;
bool DoVisualBBox = true;
// strings with the names of possible bbox types
int nboxT = 2;
ON_wString ALLBoxString;
ALLBoxString.Format( L"AxisAlignedBBox");
ON_wString OrientBoxString;
OrientBoxString.Format( L"OrientedBBox");
CRhinoCommandOptionValue Typelist_items[2];
Typelist_items[0] = RHCMDOPTVALUE(ALLBoxString);
Typelist_items[1] = RHCMDOPTVALUE(OrientBoxString);
// names of bbox types
ON_ClassArray<ON_wString> bboxtype_names;
bboxtype_names.Append(ALLBoxString);
bboxtype_names.Append(OrientBoxString);
CRhinoGetOption BBOpt;
BBOpt.SetCommandPrompt( L"CiE BBox Options" );
BBOpt.AcceptNothing();
// add the command options
int m_list_index = 0;
double m_epsVal = EPS;
double maxEps = 1.0;
double minEps = 1.0E-10;
int doVisualFlag = 1;
for(;;)
{
BBOpt.ClearCommandOptions();
int nOpts_BboxType = BBOpt.AddCommandOptionList( RHCMDOPTNAME(L"BBoxType"), 2, Typelist_items,m_list_index );
int nOpts_BboxEPS = BBOpt.AddCommandOptionNumber( RHCMDOPTNAME(L"BBoxEPS"), &m_epsVal, L"BBox epsilon", FALSE, minEps, maxEps, 0 );
int nOpts_BboxVisual = BBOpt.AddCommandOptionInteger( RHCMDOPTNAME(L"doVisualize"), &doVisualFlag, L"BBox visualization", 0, 1 );
// Do the getstring
CRhinoGet::result res = BBOpt.GetOption();
// User pressed ESC
if( res == CRhinoGet::cancel )
return CRhinoCommand::cancel;
// User pressed ENTER
if( res == CRhinoGet::nothing )
{
break;
}
if( res != CRhinoGet::option )
return CRhinoCommand::cancel;
// get option index
const CRhinoCommandOption* option = BBOpt.Option();
if( !option )
return CRhinoCommand::failure;
int option_index = option->m_option_index;
// eps value was modified
if( option_index == nOpts_BboxEPS )
{
continue;
}
// visualization flag was modified
if( option_index == nOpts_BboxVisual )
{
if (! (doVisualFlag > 0 && doVisualFlag < 1))
doVisualFlag = 0;
continue;
}
// type of bbox was modified
if( option_index == nOpts_BboxType )
{
m_list_index = option->m_list_option_current;
if (! (m_list_index > 0 && m_list_index < bboxtype_names.Count()))
m_list_index = 0;
continue;
}
}
// evaluate final option settings
if(doVisualFlag == 0) DoVisualBBox = false;
if(doVisualFlag == 1) DoVisualBBox = true;
if (m_list_index >= 0 && m_list_index <= 1)
desBBoxType = BBoxType(m_list_index);
if (m_epsVal >= minEps && m_epsVal <= maxEps)
BBoxEps = m_epsVal;
// *** Seelct faces for BBox generation ***
// array with faces to analyse
ON_SimpleArray<const CRhinoObject*> Objects;
// first the user should select objects
CRhinoGetObject GetO;
GetO.EnablePreSelect( TRUE );
// only faces selectable
GetO.SetGeometryFilter( CRhinoGetObject::surface_object );
GetO.SetCommandPrompt( L"Select faces to compute bbox on" );
// select some
CRhinoGet::result res = GetO.GetObjects(1,0 );
if( res != CRhinoGet::object )
{
// failed
return GetO.CommandResult();
}
else
{
// store select objects
int i, count = GetO.ObjectCount();
for( i = 0; i < count; i++ )
{
const CRhinoObjRef& obj_ref = GetO.Object( i );
const CRhinoObject* obj = obj_ref.Object();
if( obj )
{
// add to object array
Objects.Append(obj);
}
}
// loop over all objects
count = Objects.Count();
for( int i = 0; i < count; i++ )
{
// ok lets create a BBox instance
if(desBBoxType == ALL_BBOX) pCiEBBOX = new CiEPlg_ALLBBox(BBoxEps);
if(desBBoxType == ORIENT_BBOX) pCiEBBOX = new CiEPlg_OrientBBox(BBoxEps);
if(pCiEBBOX == 0)
return CRhinoCommand::failure;
// compute bounding box
const CRhinoObject* aObj = Objects[i];
if(aObj){
// call routine to compute box of those selected shapes
// ********* YOUR JOB ***
if(pCiEBBOX->computeBBox(aObj) != CRhinoCommand::success)
return CRhinoCommand::failure;
// ********* YOUR JOB ***
// add to shape
// first get objects uuid: http://wiki.mcneel.com/developer/sdksamples/getuuid
ON_UUID uuid = aObj->Attributes().m_uuid;
// add
CiEPlg_Shape* pCiEPlg_Shape = CiEPlg_Shape::get_Instance();
if( pCiEPlg_Shape->addBBox2Shape(uuid,pCiEBBOX) != CRhinoCommand::success)
return CRhinoCommand::failure;
// visualize if desired
// ********* YOUR JOB ***
if(DoVisualBBox) {
if(pCiEBBOX->doVisualBBox() != CRhinoCommand::success)
return CRhinoCommand::failure;
}
// ********* YOUR JOB ***
}
}
}
// return
return CRhinoCommand::success;
}
//
// END CiEBBox command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
So my first question is about this piece of code:
// get type of desired bbox (oriented or axis aligned)
// http://wiki.mcneel.com/developer/sdksamples/commandlineoptions
// http://wiki.mcneel.com/developer/sdksamples/setactiveview
How am I supposed to do that in this context? … I know … It isn’t easy … Thanks for anything!!!