Пример #1
0
void Tr21Stokes :: computeExternalForcesVector(FloatArray &answer, TimeStep *tStep)
{
    FloatArray vec;

    answer.clear();

    int nLoads = this->boundaryLoadArray.giveSize() / 2;
    for ( int i = 1; i <= nLoads; i++ ) {  // For each Neumann boundary condition
        int load_number = this->boundaryLoadArray.at(2 * i - 1);
        int load_id = this->boundaryLoadArray.at(2 * i);
        Load *load = this->domain->giveLoad(load_number);
        bcGeomType ltype = load->giveBCGeoType();

        if ( ltype == EdgeLoadBGT ) {
            this->computeBoundarySurfaceLoadVector(vec, static_cast< BoundaryLoad * >(load), load_id, ExternalForcesVector, VM_Total, tStep);
            answer.add(vec);
        }
    }

    BodyLoad *bload;
    nLoads = this->giveBodyLoadArray()->giveSize();
    for ( int i = 1; i <= nLoads; i++ ) {
        Load *load = domain->giveLoad( bodyLoadArray.at(i) );
	if ((bload = dynamic_cast<BodyLoad*>(load))) {
	  bcGeomType ltype = load->giveBCGeoType();
	  if ( ltype == BodyLoadBGT && load->giveBCValType() == ForceLoadBVT ) {
            this->computeLoadVector(vec, bload, ExternalForcesVector, VM_Total, tStep);
            answer.add(vec);
	  }
        }
    }
}
Пример #2
0
void
CrundDriver::runOperations(Load& load, int nOps) {
    beginOps(nOps);
    load.clearData();
    load.runOperations(nOps);
    finishOps(nOps); 
}
Пример #3
0
void
SUPGElement :: computeBCLhsPressureTerm_MB(FloatMatrix &answer, TimeStep *tStep)
{
    bcType boundarytype;
    int nLoads = 0;
    //bcType loadtype;
    FloatMatrix helpMatrix;
    // loop over boundary load array
    answer.clear();

    nLoads = this->giveBoundaryLoadArray()->giveSize() / 2;

    if ( nLoads ) {
        for ( int i = 1; i <= nLoads; i++ ) {
            int n = boundaryLoadArray.at(1 + ( i - 1 ) * 2);
            int side = boundaryLoadArray.at(i * 2);
            Load *load = domain->giveLoad(n);
            boundarytype = load->giveType();
            if ( boundarytype == OutFlowBC ) {
                this->computeOutFlowBCTerm_MB(helpMatrix, side, tStep);
                answer.add(helpMatrix);
            } else {
                //_warning("computeForceLoadVector : unsupported load type class");
            }
        }
    }
}
Пример #4
0
void Tr21Stokes :: computeLoadVector(FloatArray &answer, TimeStep *tStep)
{
    int i, load_number, load_id;
    Load *load;
    bcGeomType ltype;
    FloatArray vec;

    int nLoads = this->boundaryLoadArray.giveSize() / 2;
    answer.resize(15);
    answer.zero();
    for ( i = 1; i <= nLoads; i++ ) {  // For each Neumann boundary condition
        load_number = this->boundaryLoadArray.at(2 * i - 1);
        load_id = this->boundaryLoadArray.at(2 * i);
        load = this->domain->giveLoad(load_number);
        ltype = load->giveBCGeoType();

        if ( ltype == EdgeLoadBGT ) {
            this->computeEdgeBCSubVectorAt(vec, load, load_id, tStep);
            answer.add(vec);
        }
    }

    nLoads = this->giveBodyLoadArray()->giveSize();
    for ( i = 1; i <= nLoads; i++ ) {
        load  = domain->giveLoad( bodyLoadArray.at(i) );
        ltype = load->giveBCGeoType();
        if ( ltype == BodyLoadBGT && load->giveBCValType() == ForceLoadBVT ) {
            this->computeBodyLoadVectorAt(vec, load, tStep);
            answer.add(vec);
        }
    }
}
Пример #5
0
//=============================================================================
// 生成
//=============================================================================
bool Load::Create(Load** outPointer , LPDIRECT3DDEVICE9 device )
{
	Load* pointer = new Load();
	if(!pointer->Initialize(device))
		return false;

	*outPointer = pointer;

	return true;
}
Пример #6
0
void
CrundDriver::reconnectDB(Load& load) {
    cout << endl
         << "------------------------------------------------------------"
         << endl
         << "renew connection ... " << endl
         << "------------------------------------------------------------"
         << endl;
    load.closeConnection();
    load.initConnection();
}
Пример #7
0
void UndoRedo::Execute()
{
	if (Mode) //Undo
	{
		if (CurrentStep == 0)
		{
			this->pManager->GetOutput()->PrintMessage("Can't Undo, press any key to continue");
			Point Temp;
			this->pManager->GetInput()->GetPointClicked(Temp);
			this->pManager->GetOutput()->PrintMessage("");
			return;
		}
		else
		{
			CurrentStep--;
			ostringstream FileName;
			FileName << "TmpFC" << CurrentStep << ".txt";
			Load *L = new Load(pManager, FileName.str());
			L->Execute();
			this->pManager->GetOutput()->PrintMessage("Undo, press any key to continue");
			Point Temp;
			this->pManager->GetInput()->GetPointClicked(Temp);
			this->pManager->GetOutput()->PrintMessage("");
			return;
		}
	}
	else //Redo
	{
		if (CurrentStep == HistoryCounter)
		{
			this->pManager->GetOutput()->PrintMessage("Can't Redo, press any key to continue");
			Point Temp;
			this->pManager->GetInput()->GetPointClicked(Temp);
			this->pManager->GetOutput()->PrintMessage("");
			return;
		}
		else
		{
			CurrentStep++;
			ostringstream FileName;
			FileName << "TmpFC" << CurrentStep << ".txt";
			Load *L = new Load(pManager, FileName.str());
			L->Execute();
			this->pManager->GetOutput()->PrintMessage("Redo, press any key to continue");
			Point Temp;
			this->pManager->GetInput()->GetPointClicked(Temp);
			this->pManager->GetOutput()->PrintMessage("");
			return;
		}
	}
}
Пример #8
0
void
SUPGElement :: computeBCLhsTerm_MB(FloatMatrix &answer, TimeStep *tStep)
{
    bcType boundarytype;
    int nLoads = 0;
    //bcType loadtype;
    FloatMatrix helpMatrix;
    // loop over boundary load array

    answer.clear();

    nLoads = this->giveBoundaryLoadArray()->giveSize() / 2;
    if ( nLoads ) {
        for ( int i = 1; i <= nLoads; i++ ) {
            int n = boundaryLoadArray.at(1 + ( i - 1 ) * 2);
            int side = boundaryLoadArray.at(i * 2);
            Load *load = domain->giveLoad(n);
            boundarytype = load->giveType();
            if ( boundarytype == SlipWithFriction ) {
                this->computeSlipWithFrictionBCTerm_MB(helpMatrix, load, side, tStep);
                answer.add(helpMatrix);
            } else if ( boundarytype == PenetrationWithResistance ) {
                this->computePenetrationWithResistanceBCTerm_MB(helpMatrix, load, side, tStep);
                answer.add(helpMatrix);
            } else {
                // OOFEM_ERROR("unsupported load type class");
            }
        }
    }

    nLoads = this->giveBodyLoadArray()->giveSize();

    if ( nLoads ) {
        bcGeomType ltype;
        for ( int i = 1; i <= nLoads; i++ ) {
            Load *load = domain->giveLoad( bodyLoadArray.at(i) );
            ltype = load->giveBCGeoType();
            if ( ( ltype == BodyLoadBGT ) && ( load->giveBCValType() == ReinforceBVT ) ) {
                this->computeHomogenizedReinforceTerm_MB(helpMatrix, load, tStep);
                answer.add(helpMatrix);
            }
        }
    }
}
Пример #9
0
void
CrundDriver::disconnectDB(Load& load) {
    cout << endl
         << "------------------------------------------------------------"
         << endl
         << "close connection ... " << endl
         << "------------------------------------------------------------"
         << endl;
    load.closeConnection();
}
Пример #10
0
void
CrundDriver::connectDB(Load& load) {
    cout << endl
         << "------------------------------------------------------------"
         << endl
         << "init connection ... " << endl
         << "------------------------------------------------------------"
         << endl;
    load.initConnection();
}
Пример #11
0
void
SUPGElement :: computeBCLhsPressureTerm_MC(FloatMatrix &answer, TimeStep *tStep)
{
    int nLoads = 0;
    //bcType loadtype;
    FloatMatrix helpMatrix;

    nLoads = this->giveBodyLoadArray()->giveSize();
    answer.clear();
    if ( nLoads ) {
        bcGeomType ltype;
        for ( int i = 1; i <= nLoads; i++ ) {
            Load *load  = domain->giveLoad( bodyLoadArray.at(i) );
            ltype = load->giveBCGeoType();
            if ( ( ltype == BodyLoadBGT ) && ( load->giveBCValType() == ReinforceBVT ) ) {
                this->computeHomogenizedReinforceTerm_MC(helpMatrix, load, tStep);
                answer.add(helpMatrix);
            }
        }
    }
}
Пример #12
0
Load createLoad(int volt,int eq,string node,double p,double q,bool off)//创建新节点
{
	Load load;
	load.setLoadVolt(volt);
	load.setLoadEq(eq);
	load.setLoadNode(node);
	load.setLoadP(p);
	load.setLoadQ(q);
	load.setLoadOff(off);
	return load;
}
Пример #13
0
void
SUPGElement2 :: computeBCRhsTerm_MB(FloatArray &answer, TimeStep *tStep)
{
    int nLoads;

    answer.clear();

    int rule = 0;
    IntegrationRule *iRule = this->integrationRulesArray [ rule ];
    FloatArray un, gVector, s, helpLoadVector;
    FloatMatrix b, nu;

    // add body load (gravity) termms
    nLoads = this->giveBodyLoadArray()->giveSize();
    for ( int i = 1; i <= nLoads; i++ ) {
        Load *load = domain->giveLoad( bodyLoadArray.at(i) );
        bcGeomType ltype = load->giveBCGeoType();
        if ( ( ltype == BodyLoadBGT ) && ( load->giveBCValType() == ForceLoadBVT ) ) {
            load->computeComponentArrayAt(gVector, tStep, VM_Total);
            if ( gVector.giveSize() ) {
                for ( GaussPoint *gp: *iRule ) {
                    this->computeUDotGradUMatrix( b, gp, tStep->givePreviousStep() );
                    this->computeNuMatrix(nu, gp);
                    double dV  = this->computeVolumeAround(gp);
                    double rho = this->giveMaterial()->give('d', gp);
                    answer.plusProduct(b, gVector, t_supg * rho * dV);
                    answer.plusProduct(nu, gVector, rho * dV);
                }
            }
        }
    }

    // integrate tractions
    // if no traction bc applied but side marked as with traction load
    // then zero traction is assumed !!!

    // loop over boundary load array
    nLoads = this->giveBoundaryLoadArray()->giveSize() / 2;
    for ( int i = 1; i <= nLoads; i++ ) {
        int n = boundaryLoadArray.at(1 + ( i - 1 ) * 2);
        int id = boundaryLoadArray.at(i * 2);
        Load *load  = domain->giveLoad(n);
        bcGeomType ltype = load->giveBCGeoType();
        if ( ltype == EdgeLoadBGT ) {
            this->computeEdgeLoadVector_MB(helpLoadVector, load, id, tStep);
            if ( helpLoadVector.giveSize() ) {
                answer.add(helpLoadVector);
            }
        } else if ( ltype == SurfaceLoadBGT ) {
            this->computeSurfaceLoadVector_MB(helpLoadVector, load, id, tStep);
            if ( helpLoadVector.giveSize() ) {
                answer.add(helpLoadVector);
            }
        } else {
            OOFEM_ERROR("unsupported load type class");
        }
    }
}
Пример #14
0
void
SUPGElement2 :: computeBCRhsTerm_MC(FloatArray &answer, TimeStep *tStep)
{
    int nLoads;
    FloatArray s, gVector, helpLoadVector;
    FloatMatrix g;

    int rule = 1;

    answer.clear();

    nLoads = this->giveBodyLoadArray()->giveSize();
    for ( int i = 1; i <= nLoads; i++ ) {
        Load *load  = domain->giveLoad( bodyLoadArray.at(i) );
        bcGeomType ltype = load->giveBCGeoType();
        if ( ( ltype == BodyLoadBGT ) && ( load->giveBCValType() == ForceLoadBVT ) ) {
            load->computeComponentArrayAt(gVector, tStep, VM_Total);
            if ( gVector.giveSize() ) {
                for ( GaussPoint *gp: *this->integrationRulesArray [ rule ] ) {
                    this->computeGradPMatrix(g, gp);
                    double dV = this->computeVolumeAround(gp);
                    answer.plusProduct(g, gVector, t_pspg * dV);
                }
            }
        }
    }

    // integrate tractions
    // if no traction bc applied but side marked as with traction load
    // then zero traction is assumed !!!

    // loop over boundary load array
    nLoads = this->giveBoundaryLoadArray()->giveSize() / 2;
    for ( int i = 1; i <= nLoads; i++ ) {
        int n = boundaryLoadArray.at(1 + ( i - 1 ) * 2);
        int id = boundaryLoadArray.at(i * 2);
        Load *load = domain->giveLoad(n);
        bcGeomType ltype = load->giveBCGeoType();
        if ( ltype == EdgeLoadBGT ) {
            this->computeEdgeLoadVector_MC(helpLoadVector, load, id, tStep);
            if ( helpLoadVector.giveSize() ) {
                answer.add(helpLoadVector);
            }
        } else if ( ltype == SurfaceLoadBGT ) {
            this->computeSurfaceLoadVector_MC(helpLoadVector, load, id, tStep);
            if ( helpLoadVector.giveSize() ) {
                answer.add(helpLoadVector);
            }
        } else {
            OOFEM_ERROR("unsupported load type class");
        }
    }
}
Пример #15
0
void
CrundDriver::runLoad(Load& load) {
    connectDB(load);

    assert(nOpsStart <= nOpsEnd && nOpsScale > 1);
    for (int i = nOpsStart; i <= nOpsEnd; i *= nOpsScale) {
        cout << endl
             << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
             << endl
             << "running load ...                [nOps=" << i << "]"
             << load.getName() << endl
             << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
             << endl;
        runSeries(load, i);
    }
    
    disconnectDB(load);
}
Пример #16
0
void
CrundDriver::runSeries(Load& load, int nOps) {
    if (nRuns == 0)
        return; // nothing to do
    
    for (int i = 1; i <= nRuns; i++) {
        // pre-run cleanup
        if (renewConnection)
            reconnectDB(load);
        
        cout << endl
             << "------------------------------------------------------------"
             << endl
             << "run " << i << " of " << nRuns << " [nOps=" << nOps << "]"
             << endl
             << "------------------------------------------------------------"
             << endl;
        runOperations(load, nOps);
    }
    
    writeLogBuffers(load.getName());
}
Пример #17
0
void
Lattice2d_mt :: computeInternalSourceRhsVectorAt(FloatArray &answer, TimeStep *atTime, ValueModeType mode)
{
    int i, j, n, nLoads;
    double dV;
    bcGeomType ltype;
    Load *load;
    IntegrationRule *iRule = integrationRulesArray [ 0 ];
    GaussPoint *gp;
    Node *nodeA, *nodeB;


    FloatArray deltaX(3), normalVector(3);
    FloatArray val, helpLoadVector, globalIPcoords;
    FloatMatrix nm;
    double k;
    answer.resize(0);

    FloatArray gravityHelp(2);

    nLoads    = this->giveBodyLoadArray()->giveSize();
    for ( i = 1; i <= nLoads; i++ ) {
        n     = bodyLoadArray.at(i);
        load  = ( Load * ) domain->giveLoad(n);
        ltype = load->giveBCGeoType();

        if ( ltype == GravityPressureBGT ) {
            //Compute change of coordinates
            nodeA   = this->giveNode(1);
            nodeB   = this->giveNode(2);
            deltaX.at(1) = nodeB->giveCoordinate(1) - nodeA->giveCoordinate(1);
            deltaX.at(2) = nodeB->giveCoordinate(2) - nodeA->giveCoordinate(2);
            deltaX.at(3) = nodeB->giveCoordinate(2) - nodeA->giveCoordinate(2);

            //Compute the local coordinate system
            gp  = iRule->getIntegrationPoint(0);

            gravityHelp.at(1) = 1.;
            gravityHelp.at(2) = -1.;

            dV  = this->computeVolumeAround(gp);
            load->computeValueAt(val, atTime, deltaX, mode);

            k = static_cast< TransportMaterial * >( this->giveMaterial() )->giveCharacteristicValue(Conductivity_hh, gp, atTime);

            double helpFactor = val.at(1) * k * dV;

            helpFactor /= pow(this->giveLength(), 2.);
            gravityHelp.times(helpFactor);

            if ( helpLoadVector.isEmpty() ) {
                helpLoadVector.resize( gravityHelp.giveSize() );
            }

            for ( j = 1; j <= gravityHelp.giveSize(); j++ ) {
                helpLoadVector.at(j) += gravityHelp.at(j);
            }
        }

        answer.add(helpLoadVector);
    }

    return;
}
Пример #18
0
void
BeamBaseElement :: computeLocalForceLoadVector(FloatArray &answer, TimeStep *tStep, ValueModeType mode)
// computes the part of load vector, which is imposed by force loads acting
// on element volume (surface).
// Why is this function taken separately ?
// When reactions forces are computed, they are computed from element::GiveRealStressVector
// in this vector a real forces are stored (temperature part is subtracted).
// so we need further subtract part corresponding to non-nodal loading.
{
    FloatArray helpLoadVector(1);
    answer.clear();

    // loop over body load array first
    int nBodyLoads = this->giveBodyLoadArray()->giveSize();
    for ( int i = 1; i <= nBodyLoads; i++ ) {
        int id = bodyLoadArray.at(i);
        Load *load = domain->giveLoad(id);
        bcGeomType ltype = load->giveBCGeoType();
        if ( ( ltype == BodyLoadBGT ) && ( load->giveBCValType() == ForceLoadBVT ) ) {
            this->computeBodyLoadVectorAt(helpLoadVector, load, tStep, mode);
            if ( helpLoadVector.giveSize() ) {
                answer.add(helpLoadVector);
            }
        } else {
            if ( load->giveBCValType() != TemperatureBVT && load->giveBCValType() != EigenstrainBVT ) {
                // temperature and eigenstrain is handled separately at computeLoadVectorAt subroutine
                OOFEM_ERROR("body load %d is of unsupported type (%d)", id, ltype);
            }
        }
    }

    // loop over boundary load array
    int nBoundaryLoads = this->giveBoundaryLoadArray()->giveSize() / 2;
    for ( int i = 1; i <= nBoundaryLoads; i++ ) {
        int n = boundaryLoadArray.at(1 + ( i - 1 ) * 2);
        int id = boundaryLoadArray.at(i * 2);
        Load *load = domain->giveLoad(n);
	BoundaryLoad* bLoad;
	if ((bLoad = dynamic_cast<BoundaryLoad*> (load))) {
	  bcGeomType ltype = load->giveBCGeoType();
	  if ( ltype == EdgeLoadBGT ) {
	    this->computeBoundaryEdgeLoadVector(helpLoadVector, bLoad, id, ExternalForcesVector, mode, tStep, false);
            if ( helpLoadVector.giveSize() ) {
	      answer.add(helpLoadVector);
            }
	  } else if ( ltype == SurfaceLoadBGT ) {
	    this->computeBoundarySurfaceLoadVector(helpLoadVector, bLoad, id, ExternalForcesVector, mode, tStep, false);
            if ( helpLoadVector.giveSize() ) {
	      answer.add(helpLoadVector);
            }
	  } else if ( ltype == PointLoadBGT ) {
            // id not used
	    this->computePointLoadVectorAt(helpLoadVector, load, tStep, mode, false);
            if ( helpLoadVector.giveSize() ) {
	      answer.add(helpLoadVector);
            }
	  } else {
            OOFEM_ERROR("boundary load %d is of unsupported type (%d)", id, ltype);
	  }
	}
    }


    // add exact end forces due to nonnodal loading applied indirectly (via sets)
    BCTracker *bct = this->domain->giveBCTracker();
    BCTracker::entryListType bcList = bct->getElementRecords(this->number);
    FloatArray help;
    
    for (BCTracker::entryListType::iterator it = bcList.begin(); it != bcList.end(); ++it) {
      GeneralBoundaryCondition *bc = this->domain->giveBc((*it).bcNumber);
      BodyLoad *bodyLoad;
      BoundaryLoad *boundaryLoad;
      if (bc->isImposed(tStep)) {
        if ((bodyLoad = dynamic_cast<BodyLoad*>(bc))) { // body load
          this->computeBodyLoadVectorAt(help,bodyLoad, tStep, VM_Total); // this one is local
          answer.add(help);
        } else if ((boundaryLoad = dynamic_cast<BoundaryLoad*>(bc))) {
          // compute Boundary Edge load vector in GLOBAL CS !!!!!!!
          this->computeBoundaryEdgeLoadVector(help, boundaryLoad, (*it).boundaryId,
					      ExternalForcesVector, VM_Total, tStep, false);
          // get it transformed back to local c.s.
          // this->computeGtoLRotationMatrix(t);
          // help.rotatedWith(t, 'n');
          answer.add(help);
        }
      }
    }
}
Пример #19
0
void TcpClient::run()
{
	char serverName[HOSTNAME_LENGTH];
	char fileName[FILENAME_LENGTH];
	char cmd[CMD_LENGTH];
	FILE * pFile = NULL;

	loader = new Load(); 

	//initilize winsocket
	if (WSAStartup(0x0202,&wsadata)!=0)
	{  
		WSACleanup();  
		err_sys("Error in starting WSAStartup()\n");
	}


	//Display name of local host and copy it to the req
	if(gethostname(req.hostname,HOSTNAME_LENGTH)!=0) //get the hostname
		err_sys("can not get the host name,program exit");
	printf("ftp_tcp starting on host: %s",req.hostname);

	do {

		printf("\n\nType name of ftp server: ");
		cin >> serverName;

		if(strcmp(serverName, "quit") != 0) {

			//Create the socket
			if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) //create the socket 
				err_sys("Socket Creating Error");

			long ipAdr = ResolveName(serverName);
			if(ipAdr == -1) {
				printf("Unable to resolve server name.\n");
			}
			else {
				//connect to the server
				ServPort=REQUEST_PORT;
				memset(&ServAddr, 0, sizeof(ServAddr));     /* Zero out structure */
				ServAddr.sin_family      = AF_INET;             /* Internet address family */
				ServAddr.sin_addr.s_addr = ipAdr;   /* Server IP address */
				ServAddr.sin_port        = htons(ServPort); /* Server port */
				if (connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) < 0) {
					printf("Failed to connect to server %s\n", serverName);
				}
				else {

					boolean correctCmd = false;
					do {
						printf("\nType the command you want to perform (get, put, list) : ");
						cin >> cmd;

						if(strcmp(cmd,"get")==0) {
							smsg.type=REQ_GET;
							correctCmd = true;
						}
						else if (strcmp(cmd,"put")==0)
						{
							smsg.type=REQ_PUT;
							correctCmd = true;
						}
						else if (strcmp(cmd,"list")==0) {
							smsg.type=REQ_LIST;
							correctCmd = true;
						}
						else {
							printf("Wrong request command.\nAvailable:\n \t\tget\n\t\tput\n\t\tlist");
							correctCmd = false;
						}
					}while(!correctCmd);

					if(smsg.type == REQ_PUT || smsg.type == REQ_GET) {
						printf("\nType name of file to be transferred:  ");
						cin >> fileName;

						strcpy_s(req.filename, FILENAME_LENGTH, fileName);

						if(smsg.type == REQ_PUT)
						{
							fopen_s(&pFile, fileName,"rb");
							if(pFile == NULL) {
								printf("\nCannot open file %s : the file might not exist, or you don't have the permissions to open it.", fileName);
								smsg.type=REQ_CANCEL;
							}
						}
					}

					//send out the message
					memcpy(smsg.buffer,&req,sizeof(req)); //copy the request to the msg's buffer
					smsg.length=sizeof(req);
					if (msg_send(sock,&smsg) != sizeof(req))
						err_sys("Sending req packet error.,exit");

					if(smsg.type != REQ_CANCEL)
						printf("\nSent request to %s, waiting...\n", serverName);

					//receive the response
					if(msg_recv(sock,&rmsg)!=rmsg.length)
						err_sys("recv response error,exit");

					//cast it to the response structure
					respp=(Resp *)rmsg.buffer;

					// File not found
					if(strcmp(respp->response, "No such a file") == 0) 
					{
						// File does not exist
						printf("\n%s\n", respp->response);
					}
					// PUT
					else if(strcmp(respp->response, "OK") == 0) 
					{
						if (pFile!=NULL){
							loader->sendFile(pFile, fileName, serverName, sock);
						}

					} // END PUT

					// GET
					else if(strcmp(respp->response, "READY") == 0) 
					{
						loader->receiveFile(fileName, serverName, sock);
					} // END GET

					// LIST
					else if(strcmp(respp->response, "List files") == 0){
						getList(serverName);
					} // END LIST

					//close the client socket
					closesocket(sock);
				}
			}
		} // END if severname = quit
		else {
			printf("\nClient closing...");
			printf("\nPress any key to quit...");
			fflush(stdin);
			getchar();
		}

	}
Пример #20
0
PyObject* Load::create(PyTypeObject* pytype, PyObject* args, PyObject* kwds)
{
  try
  {
    // Pick up the operation
    PyObject* oper = PyDict_GetItemString(kwds,"operation");
    if (!oper)
      throw DataException("missing operation on Load");
    if (!PyObject_TypeCheck(oper, Operation::metadata->pythonClass))
      throw DataException("load operation must be of type operation");

    // Pick up the resource
    PyObject* res = PyDict_GetItemString(kwds,"resource");
    if (!res)
      throw DataException("missing resource on Load");
    if (!PyObject_TypeCheck(res, Resource::metadata->pythonClass))
      throw DataException("load resource must be of type resource");

    // Pick up the quantity
    PyObject* q1 = PyDict_GetItemString(kwds,"quantity");
    double q2 = q1 ? PythonData(q1).getDouble() : 1.0;

    // Pick up the effective dates
    DateRange eff;
    PyObject* eff_start = PyDict_GetItemString(kwds,"effective_start");
    if (eff_start)
    {
      PythonData d(eff_start);
      eff.setStart(d.getDate());
    }
    PyObject* eff_end = PyDict_GetItemString(kwds,"effective_end");
    if (eff_end)
    {
      PythonData d(eff_end);
      eff.setEnd(d.getDate());
    }

    // Create the load
    Load *l = new LoadDefault(
      static_cast<Operation*>(oper),
      static_cast<Resource*>(res),
      q2, eff
    );

    // Iterate over extra keywords, and set attributes.   @todo move this responsibility to the readers...
    if (l)
    {
      PyObject *key, *value;
      Py_ssize_t pos = 0;
      while (PyDict_Next(kwds, &pos, &key, &value))
      {
        PythonData field(value);
        PyObject* key_utf8 = PyUnicode_AsUTF8String(key);
        DataKeyword attr(PyBytes_AsString(key_utf8));
        Py_DECREF(key_utf8);
        if (!attr.isA(Tags::effective_end) && !attr.isA(Tags::effective_start)
          && !attr.isA(Tags::operation) && !attr.isA(Tags::resource)
          && !attr.isA(Tags::quantity) && !attr.isA(Tags::type)
          && !attr.isA(Tags::action))
        {
          const MetaFieldBase* fmeta = l->getType().findField(attr.getHash());
          if (!fmeta && l->getType().category)
            fmeta = l->getType().category->findField(attr.getHash());
          if (fmeta)
            // Update the attribute
            fmeta->setField(l, field);
          else
            l->setProperty(attr.getName(), value);;
        }
      };
    }

    // Return the object
    Py_INCREF(l);
    return static_cast<PyObject*>(l);
  }
  catch (...)
  {
    PythonType::evalException();
    return NULL;
  }
}
Пример #21
0
int main(){

// build hierarchy

	Duration duration;
	Manpower manpower;
	Load load;
	Conflicts conflicts;

	Worker* joe = new Worker("Joe", "Cole");
	Worker* bob = new Worker("Bob", "Marley");
	Worker* sue = new Worker("Sue", "Oyunlari");
	Worker* sam = new Worker("Sam", "Oliver");
	Worker* kid = new Worker("Kid", "Johnson");

	Equipment* hammer = new Equipment(17, "hammer");
	Equipment* drill = new Equipment(23, "drill");
	Equipment* truck = new Equipment(96, "truck");

	vector< Resource* >* res1 = new vector< Resource* >();

	res1->push_back( kid );
	res1->push_back( drill );
	res1->push_back( truck );
	res1->push_back( bob );

	vector< Resource* >* res2 = new vector< Resource* >();

	res2->push_back( sue );
	res2->push_back( sam );

	vector< Resource* >* res3 = new vector< Resource* >();

	res3->push_back( sam );
	res3->push_back( drill );
	res3->push_back( kid );

	vector< Resource* >* res4 = new vector< Resource* >();

	res4->push_back( sam );
	res4->push_back( drill );
	res4->push_back( hammer );

	vector< Resource* >* res5 = new vector< Resource* >();

	res5->push_back( sam );
	res5->push_back( kid );
	res5->push_back( drill );
	res5->push_back( hammer );

	vector< Resource* >* res6 = new vector< Resource* >();

	res6->push_back( bob );
	res6->push_back( truck );
	res6->push_back( drill );
	res6->push_back( hammer );

	vector< Resource* >* res7 = new vector< Resource* >();

	res7->push_back( bob );
	res7->push_back( sue );

	vector< Resource* >* res8 = new vector< Resource* >();

	res8->push_back( bob );
	res8->push_back( kid );

	vector< Resource* >* res9 = new vector< Resource* >();

	res9->push_back( sam );
	res9->push_back( drill );
	res9->push_back( kid );
	res9->push_back( bob );

	vector< Resource* >* res10 = new vector< Resource* >();

	res10->push_back( sam );
	res10->push_back( truck );
	res10->push_back( kid );

	Task* simple1 = new SimpleTask( 4, "do this", res1 );
	Task* simple2 = new SimpleTask( 4, "do that", res2 );
	Task* simple3 = new SimpleTask( 1, "sub-task b", res3 );
	Task* simple4 = new SimpleTask( 2, "sub-task c", res4 );
	Task* simple5 = new SimpleTask( 1, "put a nail", res5 );
	Task* simple6 = new SimpleTask( 2, "break a wall", res6 );
	Task* simple7 = new SimpleTask( 2, "something", res7 );
	Task* simple8 = new SimpleTask( 4, "something else", res8 );
	Task* simple9 = new SimpleTask( 4, "make a hole", res9 );
	Task* simple10 = new SimpleTask( 4, "drive kid home", res10 );


	vector< Task* >* tasks1 = new vector< Task* >();

	tasks1->push_back( simple1 );
	tasks1->push_back( simple2 );

	vector< Resource* >* res11 = new vector< Resource* >();

	res11->push_back( kid );
	res11->push_back( sam );
	res11->push_back( truck );
	res11->push_back( drill );

	Task* dedicated2 = new DedicatedTask( 3, "sub-task a", tasks1, res11 );

	vector< Task* >* tasks2 = new vector< Task* >();

	tasks2->push_back( simple9 );
	tasks2->push_back( simple10 );

	vector< Resource* >* res12 = new vector< Resource* >();

	res12->push_back( sam );
	res12->push_back( hammer );
	res12->push_back( truck );
	res12->push_back( kid );

	Task* dedicated3 = new DedicatedTask( 3, "sub-sub-sub task", tasks2, res12 );

	vector< Task* >* tasks3 = new vector< Task* >();

	tasks3->push_back( simple7 );
	tasks3->push_back( simple8 );
	tasks3->push_back( dedicated3 );

	Task* project2 = new ProjectTask( "sub-sub task", tasks3 );

	vector< Task* >* tasks4 = new vector< Task* >();

	tasks4->push_back( simple5 );
	tasks4->push_back( simple6 );
	tasks4->push_back( project2 );

	Task* project1 = new ProjectTask( "sub-task d", tasks4 );

	vector< Task* >* tasks5 = new vector< Task* >();

	tasks5->push_back( dedicated2 );
	tasks5->push_back( simple3 );
	tasks5->push_back( simple4 );
	tasks5->push_back( project1 );

	vector< Resource* >* res13 = new vector< Resource* >();

	res13->push_back( sue );
	res13->push_back( kid );

	Task* dedicated1 = new DedicatedTask( 1, "sub-sub-sub task", tasks5, res13 );

// ask queries

	cout << "Duration: " << duration.calc( dedicated1 ) << endl;
	cout << "Manpower: " << manpower.calc( dedicated1 ) << endl;
	cout << "Load: " << load.calc( dedicated1 ) << endl;
	cout << "Conflicts: ";

	set< Resource* > conflictsSet = conflicts.calc( dedicated1 );

    for(	set< Resource* >::iterator iter = conflictsSet.begin();
    		iter != conflictsSet.end();
    		++iter ) {

		cout<< (*iter)->getName() << " ";
    }

	cout << endl;


//delete

	delete( joe );
	delete( bob );
	delete( sue );
	delete( sam );
	delete( kid );

	delete( hammer );
	delete( drill );
	delete( truck );

	delete( res1 );
	delete( res2 );
	delete( res3 );
	delete( res4 );
	delete( res5 );
	delete( res6 );
	delete( res7 );
	delete( res8 );
	delete( res9 );
	delete( res10 );
	delete( res11 );
	delete( res12 );
	delete( res13 );

	delete( tasks1 );
	delete( tasks2 );
	delete( tasks3 );
	delete( tasks4 );
	delete( tasks5 );

	delete( simple1 );
	delete( simple2 );
	delete( simple3 );
	delete( simple4 );
	delete( simple5 );
	delete( simple6 );
	delete( simple7 );
	delete( simple8 );
	delete( simple9 );
	delete( simple10 );

	delete( dedicated2 );
	delete( dedicated3 );
	delete( project2 );
	delete( project1 );
	delete( dedicated1 );

	return 0;
}
Пример #22
0
Info::Info(QWidget *parent) :
QWidget(parent)
{
	setObjectName("Info");
	isStay = isPoped = updating = false;
	Utils::setGround(this, Qt::white);
	duration = -1;
	animation = new QPropertyAnimation(this, "pos", this);
	animation->setDuration(200);
	animation->setEasingCurve(QEasingCurve::OutCubic);
	timeT = new QLabel(tr("Time"), this);
	volmT = new QLabel(tr("Volume"), this);
	timeS = new QSlider(this);
	volmS = new QSlider(this);
	timeS->setOrientation(Qt::Horizontal);
	volmS->setOrientation(Qt::Horizontal);
	timeS->setRange(0, 0);
	volmS->setRange(0, 100);
	timeS->setValue(0);
	volmS->setValue(Config::getValue("/Playing/Volume", 50));
	timeS->setTracking(false);
	connect(timeS, &QSlider::valueChanged, [this](int _time){
		if (duration != -1 && !updating){
			APlayer::instance()->setTime(duration*_time / 400);
		}
	});
	connect(volmS, &QSlider::sliderMoved, [this](int _volm){
		QPoint p;
		p.setX(QCursor::pos().x());
		p.setY(volmS->mapToGlobal(volmS->rect().center()).y());
		QToolTip::showText(p, QString::number(_volm));
	});
	connect(volmS, &QSlider::valueChanged, [this](int _volm){
		if (!updating){
			APlayer::instance()->setVolume(_volm);
		}
	});
	playB = new QPushButton(this);
	stopB = new QPushButton(this);
	playI = QIcon::fromTheme("media-playback-start", QIcon(":/Picture/play.png"));
	stopI = QIcon::fromTheme("media-playback-stop", QIcon(":/Picture/stop.png"));
	pausI = QIcon::fromTheme("media-playback-pause", QIcon(":/Picture/pause.png"));
	playB->setIcon(playI);
	stopB->setIcon(stopI);
	playA = new QAction(playI, tr("Play"), this);
	stopA = new QAction(stopI, tr("Stop"), this);
	playA->setObjectName("Play");
	stopA->setObjectName("Stop");
	QList<QKeySequence> playS;
	playS << Config::getValue("/Shortcut/Play", QString("Space")) <<
		Qt::Key_MediaPlay <<
		Qt::Key_MediaPause <<
		Qt::Key_MediaTogglePlayPause;
	playA->setShortcuts(playS);
	stopA->setShortcut(Config::getValue("/Shortcut/Stop", QString()));
	addAction(playA);
	addAction(stopA);
	connect(playA, SIGNAL(triggered()), APlayer::instance(), SLOT(play()));
	connect(stopA, SIGNAL(triggered()), APlayer::instance(), SLOT(stop()));
	connect(playB, &QPushButton::clicked, playA, &QAction::trigger);
	connect(stopB, &QPushButton::clicked, stopA, &QAction::trigger);
	duraT = new QLabel(this);
	duraT->setAlignment(Qt::AlignRight | Qt::AlignBottom);
	duraT->setText("00:00/00:00");
	danmV = new MTableView(this);
	danmV->setWordWrap(false);
	danmV->setSelectionBehavior(QAbstractItemView::SelectRows);
	danmV->setSelectionMode(QAbstractItemView::ExtendedSelection);
	danmV->verticalHeader()->hide();
	danmV->setAlternatingRowColors(true);
	danmV->setContextMenuPolicy(Qt::CustomContextMenu);
	danmV->setModel(Danmaku::instance());
	QHeaderView *header;
	header = danmV->horizontalHeader();
	header->setSectionResizeMode(0, QHeaderView::Fixed);
	header->setSectionResizeMode(1, QHeaderView::Stretch);
	header->setHighlightSections(false);
	resizeHeader();
	header = danmV->verticalHeader();
	header->setDefaultSectionSize(22.5*logicalDpiY() / 72);
	connect(Danmaku::instance(), &Danmaku::layoutChanged, this, &Info::resizeHeader);
	connect(danmV, &QTableView::doubleClicked, [this](QModelIndex index){
		APlayer::instance()->setTime(((Comment *)(index.data(Qt::UserRole).value<quintptr>()))->time);
	});

	QAction *saveA = new QAction(tr("Save Danmaku to File"), this);
	saveA->setObjectName("Save");
	saveA->setShortcut(Config::getValue("/Shortcut/Save", QString()));
	saveA->setEnabled(false);
	connect(saveA, &QAction::triggered, [](){
		QFileDialog save(lApp->mainWidget(), tr("Save File"));
		save.setAcceptMode(QFileDialog::AcceptSave);
		QFileInfo info(APlayer::instance()->getMedia());
		if (info.isFile()){
			save.setDirectory(info.absolutePath());
			save.selectFile(info.completeBaseName());
		}
		else{
			save.setDirectory(List::instance()->defaultPath(Utils::Danmaku));
		}
		save.setDefaultSuffix("json");
		QStringList type;
		type << tr("Bilibili Danmaku Format (*.xml)") << tr("AcFun Danmaku Format (*.json)");
		save.setNameFilters(type);
		save.connect(&save, &QFileDialog::filterSelected, [&](QString filter){
			save.setDefaultSuffix(filter.indexOf("xml") == -1 ? "json" : "xml");
		});
		if (save.exec() == QDialog::Accepted){
			QStringList file = save.selectedFiles();
			if (file.size() == 1){
				Danmaku::instance()->saveToFile(file.first());
			}
		}
	});
	danmV->addAction(saveA);

	QAction *fullA = new QAction(tr("Full Danmaku"), this);
	fullA->setObjectName("Char");
	fullA->setShortcut(Config::getValue("/Shortcut/Char", QString()));
	fullA->setEnabled(false);
	connect(fullA, &QAction::triggered, [](){
		Load *load = Load::instance();
		for (const Record &r : Danmaku::instance()->getPool()){
			if (load->canFull(&r)){
				load->fullDanmaku(&r);
			}
		}
	});
	danmV->addAction(fullA);

	connect(Danmaku::instance(), &Danmaku::modelReset, [=](){
		const QList<Record> &pool = Danmaku::instance()->getPool();
		fullA->setEnabled(false);
		for (const Record &r : pool){
			if (Load::instance()->canFull(&r)){
				fullA->setEnabled(true);
				break;
			}
		}
		saveA->setEnabled(!pool.isEmpty());
	});

	connect(danmV, &QTableView::customContextMenuRequested, [=](QPoint p){
		QMenu menu(this);
		QList<const Comment *>selected;
		for (const QModelIndex &index : danmV->selectionModel()->selectedRows()){
			selected.append((Comment *)index.data(Qt::UserRole).value<quintptr>());
		}
		if (!selected.isEmpty()){
			connect(menu.addAction(tr("Copy Danmaku")), &QAction::triggered, [&](){
				QStringList list;
				for (const Comment *c : selected){
					list.append(c->string);
				}
				qApp->clipboard()->setText(list.join('\n'));
			});
			connect(menu.addAction(tr("Eliminate The Sender")), &QAction::triggered, [&](){
				for (const Comment *c : selected){
					if (!c->sender.isEmpty()){
						Shield::instance()->insert("u=" + c->sender);
					}
				}
				Danmaku::instance()->parse(0x2);
			});
			for (const Comment *c : selected){
				if (Shield::instance()->contains("u=" + c->sender)){
					connect(menu.addAction(tr("Recover The Sender")), &QAction::triggered, [&](){
						for (const Comment *c : selected){
							Shield::instance()->remove("u=" + c->sender);
						}
						Danmaku::instance()->parse(0x2);
					});
					break;
				}
			}
			menu.addSeparator();
		}
		menu.addAction(fullA);
		connect(menu.addAction(tr("Edit Blocking List")), &QAction::triggered, [this](){
			Prefer::exec(lApp->mainWidget(), 3);
		});
		connect(menu.addAction(tr("Edit Danmaku Pool")), &QAction::triggered, [this](){
			Editor::exec(lApp->mainWidget(), 2);
		});
		connect(menu.addAction(tr("Clear Danmaku Pool")), &QAction::triggered, Danmaku::instance(), &Danmaku::clearPool);
		menu.addAction(saveA);
		isStay = 1;
		menu.exec(danmV->viewport()->mapToGlobal(p));
		isStay = 0;
	});

	animation = new QPropertyAnimation(this, "pos", this);
	animation->setDuration(200);
	animation->setEasingCurve(QEasingCurve::OutCubic);
	connect(animation, &QPropertyAnimation::finished, [this](){
		if (!isPoped){
			hide();
			lApp->mainWidget()->setFocus();
		}
	});

	connect(APlayer::instance(), &APlayer::timeChanged, this, &Info::setTime);
	connect(APlayer::instance(), &APlayer::volumeChanged, [this](int volume){
		updating = 1;
		volmS->setValue(volume);
		updating = 0;
	});
	connect(APlayer::instance(), &APlayer::begin, [this](){
		setDuration(APlayer::instance()->getDuration());
	});
	connect(APlayer::instance(), &APlayer::reach, [this](){
		setDuration(-1);
	});
	connect(APlayer::instance(), &APlayer::stateChanged, [this](int state){
		bool playing = state == APlayer::Play;
		playB->setIcon(playing ? pausI : playI);
		playA->setIcon(playing ? pausI : playI);
		playA->setText(playing ? tr("Pause") : tr("Play"));
	});
	hide();
}