Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Custom Setup Sheet Data from NC FILE C# :


Recommended Posts

On 12/18/2019 at 5:30 AM, content creator said:

I wasn't trying to give that impression 😕 I want to learn..I was just giving my point of view, anyway thanks for your comments.. good luck to you. 

I wasn't trying to be short; you just seem to be in a "I need this to work" situation and not a "I need this to work AND be maintainable, well organized, etc." situation.  Take everything you read below with a grain of salt; I'm largely self-taught and this is not my field of expertise.      

 

Anyway, I took a look at your code over the holiday break.  At this point I only have a few of your functions refactored; if time allows I’ll do more.   

I made this a CLI/CLR project with a WPF interface so I could quickly test everything.  I also moved to a more traditional project layout with definitions in the header files and implementations in the source files.    

The first thing I noticed is that you have two functions that do almost the same thing; BlankAllNonSolidEnts and UnBlankAllNonSolidEnts.  I merged BlankAllNonSolidEnts and UnBlankAllNonSolidEnts into one method BlankUnblankAllNonSolids. 

int APIToolsNative::APITools::BlankUnblankAllNonSolids(bool unblank)
{
	int numberOfEntitesModified = 0;

	auto entityPointer = db_start;

	while (entityPointer != nullptr) 
	{	
		if (entityPointer->eptr->id != SOLID_ID)
		{	
			numberOfEntitesModified++;

			if (unblank)
			{
				sel_bit_turn_off(entityPointer->eptr, BLANK_BIT);
				entityPointer->eptr->color = MC_RED;
			}
			else
			{
				sel_bit_turn_on(entityPointer->eptr, BLANK_BIT);
			}

			write_ent_sel(entityPointer->eptr, entityPointer->eptr->eptr);
		}

		entityPointer = entityPointer->next;
	}

	if (numberOfEntitesModified > 0)
		repaint_graphics();

	return numberOfEntitesModified;
}

In addition to combining the functions, I went with a while loop to traverse the linked list.

You can review everything I’ve done on my GitHub 

Hope that helps.

Link to comment
Share on other sites
6 hours ago, Zaffin said:

; you just seem to be in a "I need this to work" situation and not a "I need this to work AND be maintainable, well organized, etc." situation.

Accurate.

I am hoping to improve in the future, since I don't necessarily need to write much new code,

6 hours ago, Zaffin said:

You can review everything I’ve done on my GitHub 

I'll check it out, thank you!

Link to comment
Share on other sites

I started working on your BreakSplines function and the following condition jumped out at me.

	if (entity.id == S_ID || entity.id == NB_ID)

This is unnecessary; S_ID and NB_ID are binary so we can use the bitwise operators and simplify things.

	if (entity.id & (S_ID | NB_ID))

Or, we can just use the SPLINE_ID definition from BaseDefines_CH.h

#define SPLINE_ID	(S_ID | NB_ID)	//!< Spline:  parametric or NURBS
	if (entity.id & SPLINE_ID)

 

Link to comment
Share on other sites

^ This is good. I like what you've done so far I had more time to look over it carefully, the refactored functions look like they may provide more efficiency and are very clear to read. :D

Link to comment
Share on other sites
3 minutes ago, Zaffin said:

Yes?


        public int CreateSilhouetteBoundary()
        {
            using (var apiTools = new APIToolsNative.APITools())
            {
                return apiTools.CreateSilhouetteBoundary();
            }
        }

 

Thanks, I think I may see what I was doing wrong, I'm writing mostly operations function right in c++/cli I can show you if you like. I've been trying to only use the ".net stuff" as much as possible.

Link to comment
Share on other sites

Very rough early version of the functions


int makendmil(int tlnum,double tooldia,double feedrate,int rpm,System::String ^ Name)
{
	Mastercam::Tools::EndMillFlatTool tool;
	tool.Diameter = tooldia;
	tool.Feed = feedrate;
	tool.Length = 2.0;
	tool.FluteLength = 0.75;
	tool.Flutes = 4;
	tool.MfgToolCode = "Code : ";
	tool.TipAngle = 180.0;
	tool.PlungeFeed = 75.0;
	tool.DiameterOffset = tlnum;
	tool.LengthOffset = tlnum;
	tool.Number = tlnum;
	tool.Name = Name;
	tool.SpindleRotation = 0;
	tool.RadiusType = Mastercam::Database::Types::ToolRadiusType::None;
	tool.RPM = rpm;
	tool.RetractFeed = 500.0;
	tool.ShoulderDia = tooldia;
	tool.ShankDia = tooldia;
	tool.ShoulderLength = 1;
	tool.IsMetric = false;


	tool.Coolant = Mastercam::Database::Types::CoolantMode::COOL_OFF;
	return tool.Commit() ? tool.Slot : 0;
}

int makecsopfromchains(int level, double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId,
	Mastercam::Operations::Types::ContourSubtypeType cntrtpe, Mastercam::Database::Types::CutterCompDir cuttercompdir,
	Mastercam::Database::Types::ChainDirectionType chndir, int FeedRate, int spindlespeed, bool tabison,int slot,bool osciateison)//, EndMillFlatTool ^ tool)
{
	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[viewId];

	Mastercam::IO::ViewManager::CPlane = views[viewId];

	Mastercam::IO::ViewManager::TPlane = views[viewId];
	Mastercam::Database::ChainManager::ChainTolerance = .015;
	const auto chains = Mastercam::Database::ChainManager::ChainAll(false, false, nullptr, chndir, level);
	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	
	//System::Windows::Forms::MessageBox::Show("chk");
	if (chains != nullptr && chains->Length != 0)
	{
	

		auto cntrop = gcnew Mastercam::Operations::ContourOperation;
		
		cntrop->AssignMillToolBySlot(slot);

		cntrop->UpdateToolSettings();

		cntrop->CutterComp.Direction = cuttercompdir;

		cntrop->CutterComp.RollCorners = Mastercam::Database::Types::CutterCompRoll::CutterCompRollAll;
		//linking params
		cntrop->Linking->FeedPlane = feedPlane;

		cntrop->DepthCuts.Enabled = true;

		cntrop->DepthCuts.CutOrderByDepth = true;

		cntrop->DepthCuts.FinishNumberCuts = 0;

		cntrop->DepthCuts.MaxRoughStep = .755;

		cntrop->DepthCuts.TaperedWalls = false;

		cntrop->DepthCuts.UseSubprogram = false;

		cntrop->Linking->Depth = depth;

		cntrop->Linking->ClearanceOn = true;

		cntrop->Linking->Clearance = clearancePlane;

		cntrop->Linking->Retract = clearancePlane;

		cntrop->Linking->RetractOn = true;

		cntrop->Linking->TopStock = topOfStock;

		cntrop->MiscValues->UseValuesFromPost = true;

		cntrop->MultiPass.Enabled = false;
		if (tabison)
		{
			cntrop->Tabs.AutomaticPosition = true;

			cntrop->Tabs.TabAll = true;

			cntrop->Tabs.Enabled = true;

			cntrop->Tabs.AutoTabByDistance = false;

			cntrop->Tabs.NumberOfTabs = 4;

			cntrop->Tabs.EntryExitMode = Mastercam::Operations::Types::TabEntryExitType::Vertical;

			cntrop->Tabs.TabThickness = 0.04;

			cntrop->Tabs.TabWidth = 0.1;
		}
		if (!tabison)
		{
			cntrop->Tabs.Enabled = false;
		
		}
		if (osciateison)
		{
			
				if (topOfStock <= .25)
				{
					cntrop->Linking->Depth = topOfStock;
					cntrop->Oscillate.MaximumDepth = 0.035 - topOfStock;
				}
			if (topOfStock <= .755 && topOfStock > .25)
			{
				cntrop->Linking->Depth = topOfStock - .05;
				cntrop->Oscillate.MaximumDepth = 0.085 - topOfStock;
			}
			if (topOfStock > .755)
			{
				cntrop->Linking->Depth = topOfStock - .25;
				cntrop->Oscillate.MaximumDepth = -.5;
			}
			cntrop->Oscillate.OscillationDistance = 4.0;
			cntrop->Oscillate.MovementType = Mastercam::Operations::Types::OscillationMovementType::Highspeed;
		}
		cntrop->ForceToolChangeOn = false;

		cntrop->BreakThrough.Enabled = false;

		cntrop->ArcFilter.Enabled = false;

		cntrop->RotaryAxis.Enabled = false;

		cntrop->CutParams.ContourSubtype = cntrtpe;

		cntrop->CutParams.InternalCornerRoundingRadius = .001;


		cntrop->PlungeRate = 75.0;

		cntrop->RetractRate = 500.0;
		//lead in 

		//entry params

		cntrop->Entry.ArcRadius = .025;

		cntrop->Entry.ArcSweep = 90.0;

		cntrop->Entry.HelixHeight = 0.0;

		cntrop->Entry.Enabled = true;

		//end lead in
		//
		cntrop->SpindleSpeed = spindlespeed;
		//set feedrate
		cntrop->FeedRate = FeedRate;

		cntrop->NCIName = "Contour #1";

		cntrop->Name = "Contour operation created via API";
		operation op = {};
		DB_LIST_ENT_PTR ptr;
		bool succf;
		cntrop->SetChainArray(chains);
		if (!cntrop->Commit())
		{
			return 0;
		}
		op.op_idn = cntrop->GetOperationID();
		operation_manager(&op, OPMGR_GET, &ptr, &succf);
		op.u.prm_cntr.ex_corner_rad = 0.001;
		op.cmn.stk_remain = 0.0;
		op.dcuts.stock_t_l = 0.0;
		operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
		operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);
	}

	return 1;
}

int makecspktopfromchains(int level, double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId,
	Mastercam::Operations::Types::ContourSubtypeType cntrtpe, Mastercam::Database::Types::CutterCompDir cuttercompdir,
	Mastercam::Database::Types::ChainDirectionType chndir, int FeedRate, int spindlespeed, bool tabison, int slot, bool osciateison)//, EndMillFlatTool ^ tool)
{
	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[viewId];

	Mastercam::IO::ViewManager::CPlane = views[viewId];

	Mastercam::IO::ViewManager::TPlane = views[viewId];

	const auto chains = Mastercam::Database::ChainManager::ChainAll(true, false, views[viewId], chndir, level);
	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	operation op = {};

	if (chains != nullptr && chains->Length != 0)
	{


		auto cntrop = gcnew Mastercam::Operations::PocketOperation;

		cntrop->AssignMillToolBySlot(slot);

		cntrop->Roughing.Enabled = true;

		cntrop->Finishing.Enabled = false;
		//linking params
		cntrop->Linking->FeedPlane = feedPlane;

		cntrop->Linking->Depth = depth;

		cntrop->DepthCuts.Enabled = true;

		cntrop->PocketRoughEntry.Helix.MaxRadius = .2;

		cntrop->PocketRoughEntry.Helix.MinRadius = .05;

		cntrop->PocketRoughEntry.Helix.ClearanceXY = .05;

		cntrop->PocketRoughEntry.Helix.ClearanceZ = .05;

		//cntrop->PocketRoughEntry.EntryMode

		cntrop->Linking->ClearanceOn = true;

		cntrop->Linking->Clearance = clearancePlane;

		cntrop->Linking->Retract = clearancePlane;

		cntrop->Linking->RetractOn = true;

		cntrop->Linking->TopStock = topOfStock;

		cntrop->MiscValues->UseValuesFromPost = true;

	
		cntrop->ForceToolChangeOn = false;

		cntrop->BreakThrough.Enabled = false;

		cntrop->RotaryAxis.Enabled = false;


		cntrop->DepthCuts.Enabled = true;

		cntrop->DepthCuts.CutOrderByDepth = true;

		cntrop->DepthCuts.FinishNumberCuts = 0;

		cntrop->DepthCuts.MaxRoughStep = .755;

		cntrop->DepthCuts.TaperedWalls = false;

		cntrop->DepthCuts.UseIslandDepths = false;

		cntrop->DepthCuts.UseSubprogram = false;

		cntrop->PlungeRate = 75.0;

		cntrop->RetractRate = 500.0;
		//lead in 

		//entry params

		//end lead in
		//
		cntrop->SpindleSpeed = spindlespeed;
		//set feedrate
		cntrop->FeedRate = FeedRate;

		cntrop->NCIName = "Pocket #1";

		cntrop->Name = "Pocket operation created via API";

		op.op_idn = cntrop->GetOperationID();
		cntrop->SetChainArray(chains);
		if (!cntrop->Commit())
		{
			return 0;
		}
		DB_LIST_ENT_PTR ptr{};
		bool succf{};
		op.op_idn = cntrop->GetOperationID();
		operation_manager(&op, OPMGR_GET, &ptr, &succf);
		op.cmn.stk_remain = 0.0;
		op.dcuts.stock_t_l = 0.0;
		op.u.prm_pkt.add_finish = false;
		op.u.prm_pkt.climb = false;
		op.u.prm_pkt.taper.on = false;
		op.u.prm_pkt.rough = true;
		op.u.prm_pkt.ch_sort.sort_method = 1;
		op.u.prm_pkt.co_spir_disp = true;
		op.u.prm_pkt.add_finish = true;
		op.u.prm_pkt.rgh_step_pct = 50;
		op.u.prm_pkt.rgh_entry.on = true;
		op.u.prm_pkt.rgh_entry.entry_type = 0;
		op.u.prm_pkt.rgh_entry.helix.angle = TWO_PI / 36;
		op.u.prm_pkt.rgh_entry.helix.z_clear = .05;
		double min = .05, max = .5;
		op.u.prm_pkt.rgh_entry.helix.rad_min = min;
		op.u.prm_pkt.rgh_entry.helix.rad_max = max;
		op.u.prm_pkt.rgh_entry.helix.xy_clear = .05;
		short stk_mde = 2;
		short cut_mthd = 2;
		op.u.prm_pkt.cp.cmp_to_tip;
		double dbl = .005;
		op.u.prm_pkt.cp.lin_tol = dbl;
		op.u.prm_pkt.cut_method = cut_mthd;
		op.u.prm_pkt.rough = true;
		op.u.prm_pkt.add_finish = false;
		op.u.prm_pkt.tool_down = true;
		short pck_typ = 0;
		op.dcuts.tool_down = true;
		op.u.prm_pkt.pock_type = pck_typ;
		op.u.prm_pkt.finish = false;
		op.u.prm_pkt.spiral_out = true;
		op.u.prm_pkt.rgh_step_pct_flat = true;
		op.u.prm_pkt.climb = false;
		operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
		operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);
	}

	return 1;
}

 

Link to comment
Share on other sites
		if (tabison)
		{
			cntrop->Tabs.AutomaticPosition = true;

			cntrop->Tabs.TabAll = true;

			cntrop->Tabs.Enabled = true;

			cntrop->Tabs.AutoTabByDistance = false;

			cntrop->Tabs.NumberOfTabs = 4;

			cntrop->Tabs.EntryExitMode = Mastercam::Operations::Types::TabEntryExitType::Vertical;

			cntrop->Tabs.TabThickness = 0.04;

			cntrop->Tabs.TabWidth = 0.1;
		}
		if (!tabison)
		{
			cntrop->Tabs.Enabled = false;
		
		}

Sorry, this just struck me funny!

I only want to write C++ when I have to; I'd much rather handle everything in C# and create a native .dll only if needed.  This is likely because I know nothing about MFC so any interface I create will be WPF.  

Link to comment
Share on other sites
7 minutes ago, Zaffin said:

orry, this just struck me funny!

How come? :p

8 minutes ago, Zaffin said:

This is likely because I know nothing about MFC so any interface I create will be WPF

I can show you how to setup an easy ui using the win32 api if you like, I have some projects kicking around. MFC is too much IMO. Very time consuming to learn and manipulate.

Link to comment
Share on other sites
#include <windows.h>
//-----------------
// Globals
//-----------------
#define ID_FILE_EXIT 1001
//-----------------
// Functions
//-----------------

//---------------------------------------------------------
// Name: WindowProc()
// Desc: The window message procedure.
//---------------------------------------------------------

//---------------------------------------------------------
// Name: WinMain()
// Desc: Application entry point. Creates several windows
//       and adds them to the docking system.
//---------------------------------------------------------
int main()
{
	HINSTANCE hInstance{}; HINSTANCE hPrevInstance{}; LPSTR lpCmdLine{}; int nShowCmd{};
	WNDCLASSEX wc,wc2;
	RECT rc;
	MSG msg;

	//-----------------
	// Create the windows
	//-----------------
	//Setup the window class
	wc.cbClsExtra = 0;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbWndExtra = 0;
	wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
	wc.hCursor = LoadCursor(0, IDC_ARROW);
	wc.hIcon = LoadIcon(GetModuleHandle(0), IDI_APPLICATION);
	wc.hIconSm = LoadIcon(GetModuleHandle(0), IDI_APPLICATION);
	wc.hInstance = GetModuleHandle(0);
	wc.lpfnWndProc = DefWindowProc;
	wc.lpszClassName = "DOCKINGWINDOW";
	wc.lpszMenuName = 0;
	wc.style = CS_HREDRAW | CS_VREDRAW;

	//Register the window class
	if (!RegisterClassEx(&wc))
	{
		//Error
		return 0;
	}
	
	auto gParent = CreateWindowEx(0, "DOCKINGWINDOW", "Parent Window", WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) / 2) - 150, (GetSystemMetrics(SM_CYSCREEN) / 2) - 150, 500, 500, 0, 0, hInstance, 0);
	if (gParent == 0)
	{
		//Error
		return 0;
	}
	HMENU hMenu, hSubMenu;
	hMenu = CreateMenu();
	hSubMenu = CreatePopupMenu();
	AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
	AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
	EnableMenuItem(GetSubMenu(GetMenu(gParent), 0), ID_FILE_EXIT, MF_DISABLED | MF_GRAYED);
	SetMenu(gParent, hMenu);
	UpdateWindow(gParent);

	//-----------------
	// The message loop
	//-----------------
	while (GetMessage(&msg, 0, 0, 0))
	{
		if (msg.message == WM_COMMAND)
		{
			if (LOWORD(msg.wParam) == ID_FILE_EXIT) {
				PostQuitMessage(0);
				return 0;
			}
			//Post a quit message


		//commands
			
		}
		TranslateMessage(&msg);
			DispatchMessage(&msg);
	}
		//Return to windows
		return msg.wParam;
	
}

Just so you know this is the total process to create a window with a menu on it and tying a function to it.

Link to comment
Share on other sites
38 minutes ago, Zaffin said:

; I'd much rather handle everything in C# and create a native .dll only if needed.

I'm basically the opposite I can't do c#, the only stuff I do these days are a few c# scripts in unity for game stuff. c++ is my jam and if I need .net I stick to f#

Link to comment
Share on other sites
  • 2 weeks later...
On 12/17/2019 at 7:46 PM, Zaffin said:

you're also allocating memory on the heap and never freeing it; that's less than ideal.

Would it be possible for you to provide me an example of what you meant by this? I would like to improve.

Link to comment
Share on other sites
On 1/15/2020 at 6:05 PM, content creator said:

Would it be possible for you to provide me an example of what you meant by this? I would like to improve.

Maybe?  Cpp isn't my jam, but I'll do my best.

Consider the below code...

#include <iostream>
#include <string>
#include <memory>

class Point
{
public:
	std::string Name;
	double X;
	double Y;

	Point();
	Point(std::string pointName, double xPosition, double yPosition);
	~Point();
};

Point::Point()
{
	Name = "Default Name";
	X = 0.0;
	Y = 0.0;
}

Point::Point(std::string pointName, double xPosition, double yPosition) : Name(pointName),  X(xPosition), Y(yPosition)
{
}

Point::~Point()
{
	std::cout << "Destructing " << Name << std::endl;
}

int main()
{
	/*Curly braces define scope; 
	this will allow us to see what happends when the below objects go out of scope. */
	{
	// A point object created on the stack.
	Point pointOne{ "Point One", 1.0, 1.0 };

	// A raw pointer created on the heap.
	auto pointTwo = new Point("Point Two", 2.0, 2.0);

	// A smart pointer.
	auto pointThree = std::make_unique<Point>("Point Three", 3.0, 3.0);
	}
}

// Output:
//	Destructing Point Three
//	Destructing Point One

Did you notice that the destructor for pointTwo wasn't called?   Because it was created with the 'new' keyword, it's our responsibility to clean it up before it goes out of scope.

This issue can largely be avoided by using smart pointers; pointThree is an example of a smart pointer. 

I suggest you check out google; there are many good videos on this subject.

Link to comment
Share on other sites
7 minutes ago, Zaffin said:

Maybe?  Cpp isn't my jam, but I'll do my best.

Consider the below code...


#include <iostream>
#include <string>
#include <memory>

class Point
{
public:
	std::string Name;
	double X;
	double Y;

	Point();
	Point(std::string pointName, double xPosition, double yPosition);
	~Point();
};

Point::Point()
{
	Name = "Default Name";
	X = 0.0;
	Y = 0.0;
}

Point::Point(std::string pointName, double xPosition, double yPosition) : Name(pointName),  X(xPosition), Y(yPosition)
{
}

Point::~Point()
{
	std::cout << "Destructing " << Name << std::endl;
}

int main()
{
	/*Curly braces define scope; 
	this will allow us to see what happends when the below objects go out of scope. */
	{
	// A point object created on the stack.
	Point pointOne{ "Point One", 1.0, 1.0 };

	// A raw pointer created on the heap.
	auto pointTwo = new Point("Point Two", 2.0, 2.0);

	// A smart pointer.
	auto pointThree = std::make_unique<Point>("Point Three", 3.0, 3.0);
	}
}

// Output:
//	Destructing Point Three
//	Destructing Point One

Did you notice that the destructor for pointTwo wasn't called?   Because it was created with the 'new' keyword, it's our responsibility to clean it up before it goes out of scope.

This issue can largely be avoided by using smart pointers; pointThree is an example of a smart pointer. 

I suggest you check out google; there are many good videos on this subject.

Thanks for the info.. I've been reading a lot about this,

right now I write everything in c++/cli project using various c# and c++ libraries.

I store the bulk of my data in vectors declared like

int get_size()
{
std::vector<int> vector_of_ints;
  int randomnumber = 1000;
 for(auto i = 0; i < randomnumber; i++;)
   {
   vector_of_ints.push_back(i);
   }
   //do something with the vector
   return i;
}

I guess that technically stores the data on the heap then it gets deallocated when the function goes out of scope, If I am understanding correctly would a vector be a good place to use a smart pointer, or would you recommend an array?

Link to comment
Share on other sites
36 minutes ago, content creator said:

Thanks for the info.. I've been reading a lot about this,

right now I write everything in c++/cli project using various c# and c++ libraries.

I store the bulk of my data in vectors declared like


int get_size()
{
std::vector<int> vector_of_ints;
  int randomnumber = 1000;
 for(auto i = 0; i < randomnumber; i++;)
   {
   vector_of_ints.push_back(i);
   }
   //do something with the vector
   return i;
}

I guess that technically stores the data on the heap then it gets deallocated when the function goes out of scope, If I am understanding correctly would a vector be a good place to use a smart pointer, or would you recommend an array?

Nope, that vector is on the stack;  it's lifetime is from declaration till it goes out of scope.  In the above example I see no reason to change anything.

I would not use a C-style array; I prefer the containers from the standard library.   

Link to comment
Share on other sites
36 minutes ago, Zaffin said:

Nope, that's a stack allocation, in the above example I see no reason to change anything.

I would not use a C-style array; I prefer the containers from the standard library.   

This is where I read that the memory is actually allocated on the heap.
https://stackoverflow.com/questions/8036474/when-vectors-are-allocated-do-they-use-memory-on-the-heap-or-the-stack

I tried using the smart pointer in a project I am converting, not sure If I am doing this right :

	System::String^ data = "data";
		System::String^ nstlist = NETHookNesting::NestingConstants::NestListExampleFile;
	auto nestListFile = System::IO::Path::Combine(System::IO::Path::Combine(Mastercam::IO::SettingsManager::UserDirectory, data), nstlist );
	auto nestingDefaultsFile = System::IO::Path::Combine(Mastercam::IO::SettingsManager::SharedDirectory, Mastercam::IO::SettingsManager::Metric ? NETHookNesting::NestingConstants::MetricNestingDefaultsFile : NETHookNesting::NestingConstants::EnglishNestingDefaultsFile);
	auto NestingFile = std::make_unique<Mastercam::Nesting::NestingFile>(nestingDefaultsFile);
      // Create an instance from nesting defaults and clear out any existing parts and sheets
	array<Mastercam::Nesting::NestingPart^>^NestingPartArray;
	array<Mastercam::Nesting::NestingSheet^>^SheetArray;
	NestingFile->SheetArray = SheetArray;
	NestingFile->PartArray = NestingPartArray;

 

Link to comment
Share on other sites
42 minutes ago, content creator said:

This is where I read that the memory is actually allocated on the heap.

The vector is on the stack and the contents are on the heap.  You did not allocate the heap memory so you do not need to free it.  When the vector goes out of scope the memory will be freed.  I don't see a reason to worry about using a smart pointer in the above example.

I'm not sure what your trying to do in the above snippet, or what the issue is.

When you look at the Mastercam SDK remember that Mastercam is 35 years old.  Most of the newer functions seem to use the STL stuff.  Alot of MFC in there too.  

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...