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

6 hours ago, Zaffin said:

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.

If the contents are being stored on the heap, what I have read about the heap, slower performance, memory fragmentation, It seems like vectors are probably good for new programmers to manage memory, but we will need to evolve. I  wonder what the implications are of storing a vector of c-arrays a specific size, maybe map would be better.

 

6 hours ago, Zaffin said:

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

I'ts not an issue, I am working on the NEthook Nesting Project, I need it to rewrite it in c++/cli since we are going to do math, I need to find  a means to simulate different nesting scenarios(probably shuffling the priority and rotation of the part using Rand) to automatically deduce the "most" efficient Nesting Pattern. It will also need to deduce the material size "x and y" from the name of the parts and have an input for a user provided string to the directory containing the parts.

 

6 hours ago, Zaffin said:



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

That is a very good point, and I haven't heard about stl, but I am watching some videos about it now, thanks for all the help.

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

If the contents are being stored on the heap, what I have read about the heap, slower performance, memory fragmentation, It seems like vectors are probably good for new programmers to manage memory, but we will need to evolve. I  wonder what the implications are of storing a vector of c-arrays a specific size, maybe map would be better.

I'm not an expert, but this likely isn't something you need to worry about.  

A (very) wise women once said "If you don't know what type of container you need, use a vector". 

If you take advantage of lambdas and iterators you can likely measure the performance between any of the STL containers just by changing the type.

Link to comment
Share on other sites

Peter,

STL Container -> Use them.

Zaffin's statement here are words of wisdom.

11 hours ago, Zaffin said:

A (very) wise women once said "If you don't know what type of container you need, use a vector". 

If you take advantage of lambdas and iterators you can likely measure the performance between any of the STL containers just by changing the type.

 

 

 

 

Link to comment
Share on other sites
3 minutes ago, Roger Martin from CNC Software said:

Peter,

STL Container -> Use them.

Zaffin's statement here are words of wisdom.

 

 

 

 

Thanks for the  reply Roger!! I will continue to use the stl containers. So far I haven't had any instances of Mastercam crashing due to memory leaks so I would say they have been working well.

Link to comment
Share on other sites

I spent about 15 hours working on the refactoring saturday, I made modifications to the logic so that the chook iterates through all the top and bottom surfaces sorting each on individually. 

Link to comment
Share on other sites
On 1/17/2020 at 5:16 AM, Zaffin said:

I'm not an expert, but this likely isn't something you need to worry about.  

In the case of vectors It seems to be okay, but when it comes to .net lists the data needs to be cleared, even if the list is not initialized with the new keyword. 

For example :

void SplineFromChainsOnLevel(const int &level4)
	{
	    //chain the geometry on a specified level : returns a chain array
		const auto chains = ChainManager::ChainAll(true, false, nullptr, Mastercam::Database::Types::ChainDirectionType::Clockwise, level4);
        //check that we have something////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (chains != nullptr && chains->Length != 0)
		{
			//convert the current geometry in chain array to parametric spline : delete the original geometry
			for (auto i = 0; i < 1; i++)
			{
				Mastercam::GeometryUtility::GeometryCreationManager::CreateParametricSplineFromChain(chains[i], 0.015, Mastercam::GeometryUtility::Types::OriginalCurvesDisposition::Delete, 500);
			}//////////////////////////////
		}
		//we need to clear the list before exiting the function or the list data will remain in memory             //maybe like this
                                   chains->Clear;
              chains = gcnew array< Mastercam::Database::Chain^ >(0);
	}

 

Link to comment
Share on other sites
7 hours ago, c++ said:

In the case of vectors It seems to be okay, but when it comes to .net lists the data needs to be cleared, even if the list is not initialized with the new keyword. 

What makes you think this?

From https://docs.microsoft.com/en-us/cpp/extensions/handle-to-object-operator-hat-cpp-component-extensions?view=vs-2019

Quote

The handle declarator (^, pronounced "hat"), modifies the type specifier to mean that the declared object should be automatically deleted when the system determines that the object is no longer accessible.

The garbage collector should manage the memory; what issue are you having?

 

Also your example has an issue, the below throws an 'E0137  expression must be a modifiable lvalue'  error.

	const auto chains = Mastercam::Database::ChainManager::ChainAll(true, 
                                                                    false, 
                                                                    nullptr, 
                                                                    Mastercam::Database::Types::ChainDirectionType::Clockwise, 
                                                                    level4);

	chains->Clear;

	//You declared chains as const, so you can't reassign it.
	chains = gcnew array< Mastercam::Database::Chain^ >(0);

 

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

//const auto chains 

auto chains

Oops I edited the gcnew bit in amd the end forgot to drop the const

I don't know exactly where, but the memory for my geometry isn't getting freed, if I program the panel using the macro then move it, it will continue to program in the same spot. I can even "import" the geometrt from one file to another. 

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

Oops I edited the gcnew bit in amd the end forgot to drop the const

I don't know exactly where, but the memory for my geometry isn't getting freed, if I program the panel using the macro then move it, it will continue to program in the same spot. I can even "import" the geometrt from one file to another. 

Without the entire project and steps to reproduce this is going to be tough to track down.

My gut says this is not a memory issue.

Link to comment
Share on other sites

Zaffin,

I uploaded my project onto my github. Please feel free to download it, the function you probably want to look at is -> void dogetgeometry() 

it is declared right above the first nethook entry point,of course you can keep and use any functions you wish, thank you.

The nethooks need a solid less than one inch thick position with the top of the solid at z0. different nethooks look for different features on the solid by calling a generic geometry creation function then assigning different pocket, contour, and drilling toolpaths to them.

Link to comment
Share on other sites

You may see me using the c++ chainmanager at some points, it works fairly well, however if you create a chain with chainmanager you need to call freechains() after or bad things will happen. 

Link to comment
Share on other sites
1 hour ago, c++ said:

Please feel free to download it, the function you probably want to look at is -> void dogetgeometry() 

I assume you mean std::vector<double>dogetgeometry()?  I could not find a void overload for dogetgeometry().

This project is in quite the state and I don't have time to dissect it (again); I'm sure someone else can help you out.

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

I assume you mean std::vector<double>dogetgeometry()?  I could not find a void overload for dogetgeometry().

Yeah, you're right std::vector<double>dogetgeometry

19 minutes ago, Zaffin said:

I'm sure someone else can help you out.

No problem, if I can't find a solution I will make a ticket with my reseller, I'm sure it is something minor and I will be kicking myself, have a great weekend!

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

 I don't have time to dissect it (again);

The work you did already was help enough, maybe I will show you again one day when I have better organized the project.

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

Why are you using memset?

That's an error, memset should be initialized to zero. Like ent entity{}

6 minutes ago, Zaffin said:

Why are you using NULL and not nullptr? 

Where is NULL,for zeroing out new DB_LIST_ENT_PTR?

Link to comment
Share on other sites

This works :


std::vector<DB_LIST_ENT_PTR>GetAllSolids()
{
	int numberOfSolidsSelected = 0;

	std::vector<DB_LIST_ENT_PTR> dblistptrvector;

	DB_LIST_ENT_PTR dbs_ptr;



	dbs_ptr = db_start;



	DB_LIST_ENT_PTR e_ptr;



	e_ptr = NULL;



	ent sldent{};



	bool bSuccf;



	for (; ; )//loop until "break;" command



	{



		get_ent(&dbs_ptr, &e_ptr, &sldent, ALIVE_BIT,//get entity//found entity pointer//found entity new pointer//entity class object//sel bit//entity type



			P_ID | L_ID | A_ID | S_ID | SURF_ID | SOLID_ID | SPLINE_ID | N_ID | W_ID | D_ID,//entity types



			&bSuccf);//entity succesfully read

		{

			if (!bSuccf) // No more entities

			{

				break; //bail no ents found

			}

			if (bSuccf)//entity found loop once

			{

				if (sldent.id == 65536) //entity is a solid

				{



					numberOfSolidsSelected++;


					dblistptrvector.push_back(sldent.eptr);
				}
			}
		}


	}



	if (numberOfSolidsSelected)
	{

		repaint_graphics();

	}

	return dblistptrvector;
}

This doesn't :

std::vector<DB_LIST_ENT_PTR>GetAllSolids()
{
	int numberOfSolidsSelected = 0;

	std::vector<DB_LIST_ENT_PTR> dblistptrvector;

	auto entityPointer = db_start;



	while (entityPointer != nullptr)

	{

		if (entityPointer->eptr->id == SOLID_ID)

		{
			if (sel_bit_is_off(BLANK_BIT, entityPointer->eptr->sel))
			{

				numberOfSolidsSelected++;


				dblistptrvector.push_back(entityPointer);
			}
		}



		entityPointer = entityPointer->next;

	}



	if (numberOfSolidsSelected)

		repaint_graphics();



	return dblistptrvector;
}

 

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...