示例#1
0
/**
 * @brief VToolUnionDetails costructor.
 * @param doc dom document container.
 * @param data dom document container.
 * @param id object id in container.
 * @param d1 first detail.
 * @param d2 second detail.
 * @param indexD1 index edge in first detail.
 * @param indexD2 index edge in second detail.
 * @param typeCreation way we create this tool.
 * @param parent parent object.
 */
VToolUnionDetails::VToolUnionDetails(VPattern *doc, VContainer *data, const quint32 &id, const VDetail &d1,
                                     const VDetail &d2, const quint32 &indexD1, const quint32 &indexD2,
                                     const Source &typeCreation, QObject *parent)
    :VAbstractTool(doc, data, id, parent), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2)
{
    if (typeCreation == Source::FromGui)
    {
        AddToFile();
    }
    else
    {
        RefreshDataInFile();
    }
}
示例#2
0
/**
 * @brief VToolShoulderPoint constructor.
 * @param doc dom document container.
 * @param data container with variables.
 * @param id object id in container.
 * @param typeLine line type.
 * @param formula string with formula length.
 * @param p1Line id first line point.
 * @param p2Line id second line point.
 * @param pShoulder id shoulder point.
 * @param typeCreation way we create this tool.
 * @param parent parent object.
 */
VToolShoulderPoint::VToolShoulderPoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
                                       const QString &formula, const quint32 &p1Line, const quint32 &p2Line,
                                       const quint32 &pShoulder, const Source &typeCreation,
                                       QGraphicsItem * parent)
    :VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder)
{
    if (typeCreation == Source::FromGui)
    {
        AddToFile();
    }
    else
    {
        RefreshDataInFile();
    }
}
示例#3
0
/**
 * @brief VToolAlongLine constuctor.
 * @param doc dom document container.
 * @param data container with variables.
 * @param id object id in container.
 * @param formula string with length formula.
 * @param firstPointId id first point of line.
 * @param secondPointId id second point of line.
 * @param typeLine line type. line type.
 * @param typeCreation way we create this tool.
 * @param parent parent object.
 */
VToolAlongLine::VToolAlongLine(VPattern *doc, VContainer *data, quint32 id, const QString &formula,
                               const quint32 &firstPointId, const quint32 &secondPointId,
                               const QString &typeLine, const Source &typeCreation,
                               QGraphicsItem *parent)
    :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId)
{

    if (typeCreation == Source::FromGui)
    {
        AddToFile();
    }
    else
    {
        RefreshDataInFile();
    }
}
示例#4
0
/**
 * @brief VToolBisector constructor.
 * @param doc dom document container.
 * @param data container with variables.
 * @param id object id in container.
 * @param typeLine line type.
 * @param formula string with formula length of bisector.
 * @param firstPointId id first point of angle.
 * @param secondPointId id second point of angle.
 * @param thirdPointId id third point of angle.
 * @param typeCreation way we create this tool.
 * @param parent parent object.
 */
VToolBisector::VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
                             const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId,
                             const quint32 &thirdPointId, const Source &typeCreation, QGraphicsItem *parent)
    :VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), thirdPointId(0)
{
    this->firstPointId = firstPointId;
    this->thirdPointId = thirdPointId;

    if (typeCreation == Source::FromGui)
    {
        AddToFile();
    }
    else
    {
        RefreshDataInFile();
    }
}
示例#5
0
/**
 * @brief VToolCutSpline constructor.
 * @param doc dom document container.
 * @param data container with variables.
 * @param id object id in container.
 * @param formula string with formula length first spline.
 * @param splineId id spline in data container.
 * @param typeCreation way we create this tool.
 * @param parent parent object.
 */
VToolCutSpline::VToolCutSpline(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
                               const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id,
                               const Source &typeCreation, QGraphicsItem *parent)
    :VToolCut(doc, data, id, formula, splineId, spl1id, spl2id, parent)
{
    RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
    RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);

    if (typeCreation == Source::FromGui)
    {
        AddToFile();
    }
    else
    {
        RefreshDataInFile();
    }
}
示例#6
0
/**
 * @brief VToolDetail constructor.
 * @param doc dom document container
 * @param data container with variables
 * @param id object id in container
 * @param typeCreation way we create this tool.
 * @param scene pointer to scene.
 * @param parent parent object
 */
VToolDetail::VToolDetail(VPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
                         VMainGraphicsScene *scene, QGraphicsItem *parent)
    :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(nullptr), sceneDetails(scene)
{
    VDetail detail = data->GetDetail(id);
    for (ptrdiff_t i = 0; i< detail.CountNode(); ++i)
    {
        switch (detail.at(i).getTypeTool())
        {
            case (Tool::NodePoint):
                InitTool<VNodePoint>(scene, detail.at(i));
                break;
            case (Tool::NodeArc):
                InitTool<VNodeArc>(scene, detail.at(i));
                break;
            case (Tool::NodeSpline):
                InitTool<VNodeSpline>(scene, detail.at(i));
                break;
            case (Tool::NodeSplinePath):
                InitTool<VNodeSplinePath>(scene, detail.at(i));
                break;
            default:
                qDebug()<<"Get wrong tool type. Ignore.";
                break;
        }
        doc->IncrementReferens(detail.at(i).getId());
    }
    this->setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
    RefreshGeometry();
    this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    this->setFlag(QGraphicsItem::ItemIsFocusable, true);
    if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
    {
        AddToFile();
        if (typeCreation != Source::FromTool)
        {
            qApp->getUndoStack()->endMacro();
        }
    }
}
示例#7
0
/**
 * @brief VToolSpline constructor.
 * @param doc dom document container.
 * @param data container with variables.
 * @param id object id in container.
 * @param typeCreation way we create this tool.
 * @param parent parent object.
 */
VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
                         QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent)
{
    const VSpline *spl = data->GeometricObject<const VSpline *>(id);
    QPainterPath path;
    path.addPath(spl->GetPath());
    path.setFillRule( Qt::WindingFill );
    this->setPath(path);
    this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
    this->setFlag(QGraphicsItem::ItemIsFocusable, true);
    this->setAcceptHoverEvents(true);

    VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
                                                                 spl->GetP1().toQPointF(), this);
    connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
            &VToolSpline::ControlPointChangePosition);
    connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
    connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
    controlPoints.append(controlPoint1);

    VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
                                                                 spl->GetP4().toQPointF(), this);
    connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
            &VToolSpline::ControlPointChangePosition);
    connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
    connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint);
    controlPoints.append(controlPoint2);

    if (typeCreation == Source::FromGui)
    {
        AddToFile();
    }
    else
    {
        RefreshDataInFile();
    }
}
示例#8
0
static void *internal_Allocate(int size, int flags, char *file, int line){
#else
static void *internal_Allocate(int size, int flags){
#endif

//	assert(size!=48);

//int log=1;
//int tmp = size-1;
//while((tmp>>=1)!=0) log++;
//printf("AllocateSize %d,%d\n",size,log);
	if(!initialized){
		heap_sem = new Semaphore();
		heap_sem->Acquire();

		#ifdef MEMORY_STATS
		thread_sem = new Semaphore();
		thread_sem->Acquire();
unsigned long dwThreadId;
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ticker, 0, 0, &dwThreadId);
//		_beginthread(&ticker,4096,0);
		thread_sem->Acquire();
//		Sleep(100000);
		#endif

		HANDLE file = CreateFileMapping((HANDLE)-1,0,PAGE_READWRITE,0,HEAP_SIZE+sizeof(Heap),0);
printf("Total shared heap space allocated = %d bytes\n",heap_bytes+=HEAP_SIZE);
		Heap *h = (Heap*)MapViewOfFile(file,FILE_MAP_WRITE,0,0,0);
		assert(h);
		first_heap = h;
		h->Next = 0;
		h->File = file;
		memset(h->Mask,0,HEAP_SIZE/BLOCK_SIZE/8);
		memset(h->Type,0,HEAP_SIZE/BLOCK_SIZE/8);
		memset(h->Size,-1,HEAP_SIZE/BLOCK_SIZE*sizeof(int));
		h->Blocks = (void*)(int(h)+sizeof(Heap));
		initialized = true;		// Assume we get no errors
		#ifdef _DEBUG
		void *block = internal_Allocate(BLOCK_SIZE-sizeof(MemHeader),flags,0,0);
		#else
		void *block = internal_Allocate(BLOCK_SIZE-sizeof(MemHeader),flags);
		#endif
		assert(block);
		if(!block){
			heap_sem->Release();
			printf("Failed!\n");
			return 0;
		}
		int _size = 32*sizeof(Fragment*);			// fixme: not 32 bits
		int log=1;
		int tmp = _size-1;
		while((tmp>>=1)!=0) log++;

		h = GetHeap(block);
		int blockn = h->GetBlock(block);
		h->Size[blockn] = size;
		h->Type[blockn/8]|=1<<(blockn&7);

		Fragments = (Fragment**)block;
		memset(Fragments,0,32*sizeof(Fragment*));	// fixme: not 32 bits

		Fragments[log] = (Fragment*)(int(block)+(2<<log));
		Fragments[log]->Next = 0;
		Fragments[log]->Prev = 0;

		for(int n=3; n<(BLOCK_SIZE-sizeof(MemHeader))>>log; n++){
			Fragment *frag = (Fragment*)(int(block)+(n<<log));
			Fragments[log]->Next = frag;
			frag->Next = 0;
			frag->Prev = Fragments[log];
			Fragments[log] = frag;
		}
		heap_sem->Release();
		#ifdef MEMORY_STATS
		total_used_history = (DynamicArray*)internal_Allocate(sizeof(DynamicArray),flags,0,0);
		total_size_history = (DynamicArray*)internal_Allocate(sizeof(DynamicArray),flags,0,0);
		total_frag_history = (DynamicArray*)internal_Allocate(sizeof(DynamicArray),flags,0,0);
		total_frags_history = (DynamicArray*)internal_Allocate(sizeof(DynamicArray),flags,0,0);
		total_blocks_history = (DynamicArray*)internal_Allocate(sizeof(DynamicArray),flags,0,0);
		total_used_history->DynamicArray::DynamicArray(DARRAY_SHARED_MEMORY);
		total_size_history->DynamicArray::DynamicArray(DARRAY_SHARED_MEMORY);
		total_frag_history->DynamicArray::DynamicArray(DARRAY_SHARED_MEMORY);
		total_frags_history->DynamicArray::DynamicArray(DARRAY_SHARED_MEMORY);
		total_blocks_history->DynamicArray::DynamicArray(DARRAY_SHARED_MEMORY);
		#endif
	}
	heap_sem->Acquire();
	int orgsize = size;
	size+=sizeof(MemHeader);
	if(size<sizeof(Fragment)) size = sizeof(Fragment);

	if(size<=BLOCK_SIZE/2){


		int log=1;
		int tmp = size-1;
		while((tmp>>=1)!=0) log++;

//printf("Frag %d!\n",log);
		if(!Fragments[log]){
//printf("Frag %d empty!\n",log);
			#ifdef _DEBUG
			void *block = internal_Allocate(BLOCK_SIZE-sizeof(MemHeader),flags,0,0);
			#else
			void *block = internal_Allocate(BLOCK_SIZE-sizeof(MemHeader),flags);
			#endif
			assert(block);
			if(!block){
				heap_sem->Release();
				assert(false);
				return 0;
			}
			Heap *h = GetHeap(block);
			int blockn = h->GetBlock(block);
			h->Size[blockn] = log;
//printf("h->Size[3] = %d\n",h->Size[3]);
			h->Type[blockn/8]|=1<<(blockn&7);

			Fragments[log] = (Fragment*)block;
			Fragments[log]->Next = 0;
			Fragments[log]->Prev = 0;

			for(int n=2; n<(BLOCK_SIZE-sizeof(MemHeader))>>log; n++){
				Fragment *frag = (Fragment*)(int(block)+(n<<log));
				Fragments[log]->Next = frag;
				frag->Next = 0;
				frag->Prev = Fragments[log];
				Fragments[log] = frag;
			}
		}

//		int frags = get_frag_count();

		MemHeader *header = (MemHeader*)Fragments[log];
//printf("Alloc: %d\n",log);
	if(Fragments[log]->Prev) Fragments[log]->Prev->Next = Fragments[log]->Next;
	if(Fragments[log]->Next) Fragments[log]->Next->Prev = Fragments[log]->Prev;
		Fragments[log] = Fragments[log]->Prev;
//DumpStuff();
//GetHeap(data);
		//#ifdef MEMORY_STATISTICS
//		heap_used+=orgsize;
		//#endif

//		frags = frags-get_frag_count();
		//printf("Alloc: %d\n",frags);
//		assert(frags==1);

		#ifdef _DEBUG
		AddToFile(header,file,line,orgsize); //1<<log);
		#endif
//printf("Alloc at %x\n",data);
//printf("Alloc(%d) %x\n",orgsize,header);
		header->size = orgsize;
//printf("a\n");
		#ifdef MEMORY_STATS
		if(file&&line){
			header->line = line;
			if(file){
				header->file = (char*)internal_Allocate(strlen(file)+1,flags,0,0);
				sprintf(header->file,"%s",file);
			}else header->file = 0;

//printf("b\n");
			MemHeader *ent = list;
			while(ent){
				if(ent->line==header->line){
					if(ent->file&&header->file){
						if(!strcmp(ent->file,header->file)){
							header->listent = ent;
							ent->size+=orgsize;
							break;
						}
					}else if(!ent->file&&!!header->file){
						header->listent = ent;
						ent->size+=orgsize;
						break;
					}
				}
				ent = ent->Next;
			}
//printf("c\n");
			if(!ent){
				MemHeader *ent = (MemHeader*)internal_Allocate(sizeof(MemHeader),flags,0,0);
				ent->size = orgsize;
				ent->file = file;
				ent->line = line;
				ent->history = (DynamicArray*)internal_Allocate(sizeof(DynamicArray),flags,0,0);
				ent->history->DynamicArray::DynamicArray(DARRAY_SHARED_MEMORY);
				header->listent = ent;
				ent->Next = list;
				list = ent;
			}
		}else header->listent = 0;
		#endif

//printf("d\n");
		heap_used+=orgsize;
//printf("Allocated %d bytes!\n",orgsize);
		heap_sem->Release();
//printf("e\n");
		return (void*)(int(header)+sizeof(MemHeader));
	}else{
示例#9
0
文件: tbg.cpp 项目: TeoTwawki/dltcep
int Ctbg::WriteIap(int fhandle)
{
  CString tmpstr;
  CString *tbgnames, *othernames;
  int esize;
  int i;
  int ret;

  ret=0;
  memcpy(iapheader.signature,"IAP",4);
  iapheader.genre=(unsigned char) get_genre();

  othernames=tbgnames=NULL;
  esize=iapfilecount*sizeof(iap_file_header);
  iapheader.totallen=sizeof(iap_header)+esize;
  if(tbgnamecount!=iapheader.tbgcount) return -1;
  if(othernamecount!=iapheader.othercount) return -1;

  tbgnames=new CString[iapheader.tbgcount];
  if(!tbgnames)
  {
    return -3; //no need of quest
  }
  othernames=new CString[iapheader.othercount];
  if(!othernames)
  {
    ret=-3;
    goto endofquest;
  }

  for(i=0;i<iapheader.tbgcount;i++)
  {
    if(AddTbgFile(i,tbgnames[i]))
    {
      ret=-2;
      goto endofquest;
    }
  }
  for(i=0;i<iapheader.othercount;i++)
  {
    if(AddOtherFile(i,othernames[i]))
    {
      ret=-2;
      goto endofquest;
    }
  }

  for(i=0;i<iapfilecount;i++)
  {
    iapfileheaders[i].nameoffset=iapheader.totallen;
    if(i<tbgnamecount)
    {
      iapfileheaders[i].namelength=tbgnames[i].GetLength();
    }
    else
    {
      iapfileheaders[i].namelength=othernames[i-tbgnamecount].GetLength();
    }
    iapheader.totallen+=iapfileheaders[i].namelength;
    iapfileheaders[i].fileoffset=iapheader.totallen;
    iapheader.totallen+=iapfileheaders[i].filelength;
  }

  if(write(fhandle,&iapheader,sizeof(iapheader) )!=sizeof(iapheader) )
  {
    ret=-2;
    goto endofquest;
  }
  esize=iapfilecount*sizeof(iap_file_header);
  if(write(fhandle,iapfileheaders,esize)!=esize)
  {
    ret=-2;
    goto endofquest;
  }

  for(i=0;i<iapheader.tbgcount;i++)
  {
    ret=AddToFile(fhandle, m_tbgnames[i], tbgnames[i], iapfileheaders[i].filelength);
    if(ret<0) goto endofquest;
  }
  for(i=0;i<iapheader.othercount;i++)
  {
    ret=AddToFile(fhandle,m_othernames[i], othernames[i], iapfileheaders[i+iapheader.tbgcount].filelength);
    if(ret<0) goto endofquest;
  }
endofquest:
  if(tbgnames) delete [] tbgnames;
  if(othernames) delete [] othernames;
  return ret;
}