/**************************************************************************
	parameters: -
	return value: -

	Starting from the head, while the current node does not equal null,
	output the nodes contents.
**************************************************************************/
void PaintingList::printAll()
{
	Painting * curr = head;
	while(NULL != curr)
	{
		curr->print();
		curr = curr->getNext();
	}

}
示例#2
0
/**************************************************************************
	parameters: Painting *
	return value: -

	Copy constructor. Preforms a deep copy on a Painting. Appends "_COPY"
	to the title to denote that it is a copy.
	
**************************************************************************/
Painting::Painting(Painting& p)
{
	ostringstream convert;
	Painting::creationCounter = Painting::creationCounter + 1;
	height = p.getHeight();
	width = p.getWidth();
	id = Painting::creationCounter;
	convert << Painting::creationCounter;
	title = p.getTitle() + "_COPY" + convert.str();
    	next = NULL;
}
/**************************************************************************
	parameters: string
	return value: Painting *

	Starting from the head, while the current node does not equal NULL,
	compare the passed in title to the current node's title. If it matches
	return current node. Otherwise continue. If current node is equal to NULL 
	return NULL (since no matching title was found).
**************************************************************************/
Painting * PaintingList::findPainting(int temp_id)
{
	Painting * curr = head;
	while(NULL != curr)
	{
		if(curr->idMatch(temp_id))
			return curr;

		curr = curr->getNext();
	}
	return NULL;

}
/**************************************************************************
	parameters: int
	return value: bool
	
	Since a paintinglist will never be empty, since it is only created
	when the user inputs a painting and an artist, we can always check
	the first item in the paintinglist.

	If the head of the list is the node to remove, then store the value at
	head in a temporary pointer and move the head to the next node in the 
	list. If the next node in the list is NULL remove the temporary pointer
	and return true (denoting that the artist should be deleted too, since
	he has no paintings). Otherwise, delete the temporary variable, and its'
	next is the new head of the list.

	If the node to delete is not the first in the list, search for it. If
	it does not equal to NULL grab its' parent and child. If the child is
	NULL then set the tail of the list to the parent (since the node to 
	delete is the last in the list), and then set the parent's next to NULL.
	Otherwise set the parents next to the child, and delete the node.
	
**************************************************************************/
bool PaintingList::removePainting(int temp_id)
{
	if(head->idMatch(temp_id))
	{
        	Painting * temp = head;
		head = head->getNext();
		
		if(NULL == head)
		{
			delete(temp);
			temp->setNext(NULL);
			head = NULL;
			tail = NULL;
			return true;
		}
		else
		{
			delete(temp);
            		temp->setNext(NULL);
			return false;
		}
	}
	
	Painting * pNodeParent = findPaintingParent(temp_id);

	if(NULL != pNodeParent)
	{
		Painting * pNode = pNodeParent->getNext();
		Painting * pNodeChild = pNode->getNext();

		delete(pNode);
        	pNode->setNext(NULL);

		if(NULL == pNodeChild)
		{
		    tail = pNodeParent;
		    pNodeParent->setNext(NULL);
		}
		else
		    pNodeParent->setNext(pNodeChild);
	}
	else
		cout << endl << "ERROR: Could not find painting with id: " << temp_id << endl;

	return false;
}
示例#5
0
/**************************************************************************
	parameters: -
	return value: -

	Destructor, deletes all dynamically allocated parts of an instance 
	of the class. As well as, the instance.
**************************************************************************/
Artist::Artist(Artist& a)
{
	cout << "Please enter a new first name: ";
	getline(cin, firstName);

	lastName = a.getLastName();
	numberOfPaintings = a.getNumberOfPaintings();

	pList = new PaintingList();
	next = NULL;
	
	int i;
	PaintingList * pl = a.getPaintingList();
	Painting * p = pl->getHead();
	for(i = 0; i < numberOfPaintings; i++, p = p->getNext())
	{	
		pList->appendToTail(p->copy());
	}
}
示例#6
0
void Painter::DrawPaintingOp(const Rect& target, const Painting& p)
{
	Size sz = target.GetSize();
	Sizef psz = p.GetSize();
	Begin();
	Translate(target.left, target.top);
	Scale(sz.cx / psz.cx, sz.cy / psz.cy);
	Paint(p);
	End();
}
示例#7
0
bool PLinkedList::_copy_node(String _title, String _fname, String _lname){
  
PNode *temp_p = NULL;



  temp_p = head;
   while(NULL != temp_p){

     if(temp_p->data->dup_painting(_title,_fname,_lname))
        break;

        temp_p = temp_p->next;
   }

   Painting p;
    p.deep_copy_(*temp_p->data);
PLinkedList::push_back(&p);
   
  return temp_p;
};
示例#8
0
/*	Change:
 *	- Global for loop variable instantiations
 *	- See below for others
 */
int main()
{
	// Changed number of records, only 4
	const int NUM = 4;
	
	// Declare new paintings
	Painting pictures[NUM];

    for(int i = 0; i < NUM; ++i)
    {
		// Declare new instance
		Painting temp;
		
		// Set the data
		temp.setData();
		
		// Check if it is famous (to increase cost)
		if(isPaintingFamous(temp))
		{
			// Create a Famous painting
			FamousPainting tempFamous(temp.getTitle(), temp.getArtist());
			
			// Copy to the temporary class, default contructor should be fine
			temp = tempFamous;
		}
		
		// Added array index
       pictures[i] = temp;
	}
	
	// Cleaned up for loop
	for (int i = 0; i < NUM; i++)
		// Added index
		pictures[i].showPainting();
	
	// Return for main function
	return 0;
}
示例#9
0
/*	Change:
 *	- See bellow for more changes
 *	- Pass painting by reference, do not invoke copy contructor
 */
bool isPaintingFamous(Painting &painting)
{
	// Setup Local Vars
	// Deafult, assume not famous
	bool isFamous = false;
	const int NUM = 4;
	string artists[NUM] = {
		"Degas",
		"Monet",
		"Picasso",
		"Rembrandt"
	};
	
	// Changed to int, no need for char
	// Fixed arraym cause segmentation fault in CC not in clang/g++
	for (int x = 0; x < NUM; x++)
		// Use passed in data, update how array displays variable
		if (painting.getArtist() == artists[x])
			// If match, fame is true
			isFamous = true;
	
	return isFamous;
}
示例#10
0
// ---------------------------------------------------------------
void LibraryDialog::slotSave()
{
  stackedWidgets->setCurrentIndex(2); //message window
  libSaveName->setText(NameEdit->text() + ".lib");

  ErrText->insert(tr("Saving library..."));

  if(!LibFile.open(QIODevice::WriteOnly)) {
    ErrText->append(tr("Error: Cannot create library!"));
    return;
  }
  QTextStream Stream;
  Stream.setDevice(&LibFile);
  Stream << "<Simgui Library " PACKAGE_VERSION " \""
	 << NameEdit->text() << "\">\n\n";

  bool Success = true, ret;

  QString tmp;
  QTextStream ts(&tmp, QIODevice::WriteOnly);

  for (int i=0; i < SelectedNames.count(); i++) {
    ErrText->insert("\n=================\n");

    QString description = "";
    if(checkDescr->checkState() == Qt::Checked)
      description = Descriptions[i];

    Stream << "<Component " + SelectedNames[i].section('.',0,0) + ">\n"
           << "  <Description>\n"
           << description
           << "\n  </Description>\n";

    Schematic *Doc = new Schematic(0, SimguiSettings.SimguiWorkDir.filePath(SelectedNames[i]));
    ErrText->insert(tr("Loading subcircuit \"%1\".\n").arg(SelectedNames[i]));
    if(!Doc->loadDocument()) {  // load document if possible
        delete Doc;
        ErrText->append(tr("Error: Cannot load subcircuit \"%1\".").
			arg(SelectedNames[i]));
        break;
    }
    Doc->DocName = NameEdit->text() + "_" + SelectedNames[i];
    Success = false;

    // save analog model
    tmp.truncate(0);
    Doc->isAnalog = true;

    ErrText->insert("\n");
    ErrText->insert(tr("Creating Simgui netlist.\n"));
    ret = Doc->createLibNetlist(&ts, ErrText, -1);
    if(ret) {
      intoStream(Stream, tmp, "Model");
      int error = 0;
      QStringList IFiles;
      SubMap::Iterator it = FileList.begin();
      while(it != FileList.end()) {
          QString f = it.data().File;
          QString ifn, ofn;
          if(it.data().Type == "SCH") {
              ifn = f + ".lst";
              ofn = ifn;
          }
          else if(it.data().Type == "CIR") {
              ifn = f + ".lst";
              ofn = ifn;
          }
          if (!ifn.isEmpty()) error += intoFile(ifn, ofn, IFiles);
          it++;
      }
      FileList.clear();
      if(!IFiles.isEmpty()) {
          Stream << "  <ModelIncludes \"" << IFiles.join("\" \"") << "\">\n";
      }
      Success = error > 0 ? false : true;
    }
    else {
        ErrText->insert("\n");
        ErrText->insert(tr("Error: Cannot create netlist for \"%1\".\n").arg(SelectedNames[i]));
    }

    // save verilog model
    tmp.truncate(0);
    Doc->isVerilog = true;
    Doc->isAnalog = false;

    ErrText->insert("\n");
    ErrText->insert(tr("Creating Verilog netlist.\n"));
    ret = Doc->createLibNetlist(&ts, ErrText, 0);
    if(ret) {
      intoStream(Stream, tmp, "VerilogModel");
      int error = 0;
      QStringList IFiles;
      SubMap::Iterator it = FileList.begin();
      while(it != FileList.end()) {
          QString f = it.data().File;
          QString ifn, ofn;
          if(it.data().Type == "SCH") {
              ifn = f + ".lst";
              ofn = f + ".v";
          }
          else if(it.data().Type == "VER") {
              ifn = f;
              ofn = ifn;
          }
          if (!ifn.isEmpty()) error += intoFile(ifn, ofn, IFiles);
          it++;
      }
      FileList.clear();
      if(!IFiles.isEmpty()) {
          Stream << "  <VerilogModelIncludes \""
                 << IFiles.join("\" \"") << "\">\n";
      }
      Success = error > 0 ? false : true;
    }
    else {
        ErrText->insert("\n");
    }

    // save vhdl model
    tmp.truncate(0);
    Doc->isVerilog = false;
    Doc->isAnalog = false;

    ErrText->insert(tr("Creating VHDL netlist.\n"));
    ret = Doc->createLibNetlist(&ts, ErrText, 0);
    if(ret) {
      intoStream(Stream, tmp, "VHDLModel");
      int error = 0;
      QStringList IFiles;
      SubMap::Iterator it = FileList.begin();
      while(it != FileList.end()) {
          QString f = it.data().File;
          QString ifn, ofn;
          if(it.data().Type == "SCH") {
              ifn = f + ".lst";
              ofn = f + ".vhdl";
          }
          else if(it.data().Type == "VHD") {
              ifn = f;
              ofn = ifn;
          }
          if (!ifn.isEmpty()) error += intoFile(ifn, ofn, IFiles);
          it++;
      }
      FileList.clear();
      if(!IFiles.isEmpty()) {
          Stream << "  <VHDLModelIncludes \""
                 << IFiles.join("\" \"") << "\">\n";
      }
      Success = error > 0 ? false : true;
      }
      else {
          ErrText->insert("\n");
      }

      Stream << "  <Symbol>\n";
      Doc->createSubcircuitSymbol();
      Painting *pp;
      for(pp = Doc->SymbolPaints.first(); pp != 0; pp = Doc->SymbolPaints.next())
        Stream << "    <" << pp->save() << ">\n";

      Stream << "  </Symbol>\n"
             << "</Component>\n\n";

      delete Doc;

      if(!Success) break;

  } // for

  LibFile.close();
  if(!Success) {
    LibFile.remove();
    ErrText->append(tr("Error creating library."));
    return;
  }

  ErrText->append(tr("Successfully created library."));
}
示例#11
0
void cBSPDemoCallbacks::OnEvent( TSREvent& _event )
{
	switch ( _event.type )
    {
        case TWISTER_KEYDOWN:
#ifdef ENABLE_EDITING
            if ( KEYDOWN( TWISTER_KEY_p ) )
            {
                Painting* pNewPainting = new Painting();
                char paintingName[ 128 ];
                sprintf( paintingName, "database//objects//painting%d.txt", g_pPaintings->m_Paintings.size() );
                pNewPainting->SetName( paintingName );
                FormulateViewMatrix( g_pCamera, pNewPainting->m_Transform );
                pNewPainting->Save();
            }
            if ( KEYDOWN( TWISTER_KEY_1 ) )
            {
                if ( g_pCurrentPainting )
                {
                    TSRMatrix4& transform = g_pCurrentPainting->m_Transform;
                    TSRMatrix4 rot;
                    rot.MakeIdent();
                    rot.IsAxisRotation( TSRVector3( 1.0f, 0.0f, 0.0f ), PI / 2.0f );
                    transform = rot * transform ;
                    g_pCurrentPainting->Save();
                }
            }
            if ( KEYDOWN( TWISTER_KEY_2 ) )
            {
                if ( g_pCurrentPainting )
                {
                    TSRMatrix4& transform = g_pCurrentPainting->m_Transform;
                    TSRMatrix4 rot;
                    rot.MakeIdent();
                    rot.IsAxisRotation( TSRVector3( 0.0f, 1.0f, 0.0f ), PI / 2.0f );
                    transform = rot * transform ;
                    g_pCurrentPainting->Save();
                }
            }
            if ( KEYDOWN( TWISTER_KEY_3 ) )
            {
                if ( g_pCurrentPainting )
                {
                    TSRMatrix4& transform = g_pCurrentPainting->m_Transform;
                    TSRMatrix4 rot;
                    rot.MakeIdent();
                    rot.IsAxisRotation( TSRVector3( 0.0f, 0.0f, 1.0f ), PI / 2.0f );
                    transform = rot * transform ;
                    g_pCurrentPainting->Save();
                }
            }
            if ( KEYDOWN( TWISTER_KEY_n ) )
            {
                g_PaintingsIndex++;
                
                if ( g_PaintingsIndex == g_pPaintings->m_Paintings.size() )
                {
                    g_PaintingsIndex = 0;
                }
                
                g_pCurrentPainting = g_pPaintings->m_Paintings[g_PaintingsIndex];
            }
            if ( KEYDOWN( TWISTER_KEY_v ) )
            {
                g_bDebugRenderLights = !g_bDebugRenderLights;
                break;
            }
#endif // ENABLE_EDITING
            if ( KEYDOWN( TWISTER_KEY_l ) )
            {
                TSRColor4 LightColor;
                LightColor.r = fastabs( m_pWorld->m_Camera.m_Fwd.x );
                LightColor.g = fastabs( m_pWorld->m_Camera.m_Fwd.y );
                LightColor.b = fastabs( m_pWorld->m_Camera.m_Fwd.z );
                LightColor.a = 4.0f;
                LightsManager()->AddPointLight( m_pWorld->m_Camera.m_Loc, LightColor, 100.0f );
            }
            if ( KEYDOWN( TWISTER_KEY_k ) )
            {
                if ( LightsManager()->m_SceneLightsContext.GetPointLightsCount() > 0 )
                {
                    SAFE_DELETE( LightsManager()->m_SceneLightsContext.m_PointLights.back() );
                    LightsManager()->m_SceneLightsContext.m_PointLights.pop_back();
                }
            }
            break;
    }
}